加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl, shell, tcl,c 互相调用

发布时间:2020-12-15 23:48:26 所属栏目:大数据 来源:网络整理
导读:perl 调用 shell system or ``(反斜杠) tcl 调用 shell exec shell shell 调用 perl c 调用 tcl or perl system(/opt/cool/tools/bin/inject_wise)? (execl(curl_nvm_sim.pl,arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,0) btw: system() calls out to sh to h
perl 调用 shell
system or ``(反斜杠)
tcl 调用 shell
exec shell
shell 调用 perl
c 调用 tcl or perl
system(/opt/cool/tools/bin/inject_wise)?

(execl(curl_nvm_sim.pl,arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,0)


btw:

system() calls out to sh to handle your command line,so you can get wildcard expansion,etc.?
exec() and its friends replace the current process image with a new process image.
With system(),your program continues running and you get back some status about the external command you called.?
With exec(),your process is obliterated.
In general,I guess you could think of system() as a higher-level interface.?
You could duplicate its functionality yourself using some combination fork(),exec(),and wait().
To answer your final question,system() causes a child process to be created,and the exec() family do not.?

You would need to use fork() for that.


http://www.cnblogs.com/finallyliuyu/archive/2012/07/19/2598930.html

1 shell echo 命令会自动加入换行符

2. $?接受exit 返回值

3.变量等于`执行脚本` ,变量获取的值为脚本最后向STDOUT输出的值

例子如下

1. perl 调用shell

1.sh中的内容

#!/usr/bin/sh
echo `date`;
exit 1;

test.pl中的内容

? 1? ?use strict;?

? 2 use warnings;??????????????????????????????????????????????????????????????????????????????????????????????
? 3 my $s=`sh 1.sh`;?????????????????????????????????????????????????????????????????????????????????????????
? 4 print STDOUT "$s";???????????????????????????????????????????????????????????????????????????????????????????
? 5 my $exitcode=$?>>8;????????????????????????????????????????????????????????????????????????????????????????????????????????????
? 6 print "$exitcoden";?

?

2 shell调用perl

shell 脚本实例

#!/usr/bin/sh
s=`perl PrepareEnvironment.pl`
echo $?;
echo $s;

3. perl中system命令,不能执行system("cd xxx");

ln -sf $s/good.dic? ../Dic/Dic/good.dic ln 命令在创建软连接时,第一个参数必须是绝对路径

touch a.txt,当a.txt存在的时候,touch的作用仅是改变文件的时间戳标识。



c 语言调用shell有两种方法:一个是system 一个是popen/pclose

c call shell with system example:

uname write file

#include "stdio.h"
#include "stdlib.h"
main () {
??????? int ret;
??????? FILE *fileptr=NULL;
??????? char ipfile[512];
??????? char ibuf[512];
??????? char os[512];
??????? char osname[512];
??????? int i;

??????? ret=system("uname -a >uname.txt");
??????? fileptr = fopen("hostname","r");
??????? printf ("ret=%dn",ret);

??????? memset (ipfile,0x00,sizeof(ipfile));
??????? memset (ibuf,sizeof(ibuf));
??????? memset (os,sizeof(os));
??????? memset (osname,sizeof(osname));

??????? sprintf(ipfile,"uname.txt"); ??????? fileptr=fopen(ipfile,"r"); ??????? if (fileptr == NULL) { ??????????????? printf ("open file fail n"); ??????????????? return; ??????? } ??????? while (fgets(ibuf,sizeof(ibuf),fileptr)!=NULL) { ??????????????? if (1 != sscanf(ibuf,"%s",&os)) { ??????????????????????? printf ("read file fail n"); ??????????????? } ??????????????? printf ("line30:ibuf=%sn",ibuf); ??????? } ??????? for (i=0;ibuf[i]!='';i++) { ??????????????? if (ibuf[i]==' ') { ??????????????????????? break; ??????????????? } else { ??????????????????????? printf ("line35:ibuf[%d]=%c n",i,ibuf[i]); ??????????????????????? osname[i]=ibuf[i]; ??????????????? } ??????? } ??????? printf ("osname=%sn",osname); ??????? pclose(fileptr); }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读