perl, shell, tcl,c 互相调用

您所在的位置:网站首页 perl执行shell脚本 perl, shell, tcl,c 互相调用

perl, shell, tcl,c 互相调用

2023-11-14 16:19| 来源: 网络整理| 查看: 265

1 perl 调用 shell: system or ``(反斜杠) 2 shell 调用 perl:http://www.cnblogs.com/finallyliuyu/archive/2012/07/19/2598930.html  3 tcl 调用 shell: exec shell tcl 中run shell脚本用exec ;这个命令超级好用 exec echo "rcc build exit in IH" | /bin/mailx -r  [email protected] -s "rcc build exit"  [email protected] 2>/dev/null 这种都可以 运行tcl文件 source.tcl中的[]相当于shell中的``。表示执行 set a [exec uname -a ] 4 c 调用 shell ,tcl or perl 4.1 system(/opt/cool/tools/bin/inject_wise)  (execl(curl_nvm_sim.pl, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, 0) 4.2  c 语言调用shell有两种方法:一个是system 一个是popen/pclose system: system("killall klogd"); popen: 对执行过程可以控制 if (NULL == (fp = popen(sCmd.c_str(), "r"))) { ...... } while (fgets(line, sizeof(line), fp)) { output += line_ptr; output += "\n"; }

5 expect 调用shell

shell在expect中很受限。 什么空格等格式一定要精确,否则就不能执行(管道|不能和command中间注意空格)

example 1:

use exec to run shell

[] to 执行 to get output

set a [ exec ls -ltr | head -2 | tail -1  ] puts "a=$a"

#check lognmake.out results:RET=0 or RET=-1 set result [ exec tail -1 lognmake.out ] puts "result=$result"

example 2: shell command can;t run well

exec ksh "cd \"$ROOT/cool/lib/apsparc\";rm -f *.so"

exec cd $ROOT/cool/lib/apsparc When you call ‘exec‘ you are creating a sub-shell.  When the exec’d program finishes, the sub-shell is terminated and you return to expect.

So ‘exec cd …’ is completely useless.  The sub-shell changes directory (but not the parent), then exits.  So the change of directory is lost.

This might have worked:  exec “cd ….; rm –f ….” because the cd and the rm would both be in the same sub-shell.

特别注意:这样执行是local 的lognmake.out。不是remote server  的lognmake.out

send "cd $ROOT/abc\r"

expect {

         timeout {puts "timeout\r"}

        "$ps1"

]

set result [ exec tail -1 lognmake.out ]

example3 :

http://forum.ubuntu.org.cn/viewtopic.php?p=109814

麻雀岁五脏俱全,expect 调用shell的框架是对的

shell 调用expect 解析。

以here文档的方式将expect脚本,送给expect解析

在expect的脚本中调用talk.sh shell

要交互的脚本(talk.sh)如下: #!/bin/bash echo "Who are you?" read who echo "Hello,$who" echo "Are you happy?" read answer echo "why?" read answe 实现自动应答的脚本auto.sh如下: #!/bin/bash expect



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3