从perl脚本调用bash脚本 [英] Call a bash script from a perl script
问题描述
我想在perl脚本一个code和需要调用在bash另一个文件。
不知道,这是做的最好的方法?我可以直接调用它使用system()?
请指导/给我一个样品的方式。
I am trying a code in perl script and need to call another file in bash. Not sure, which is the best way to do that? can I directly call it using system() ? Please guide/ show me a sample way.
从我到目前为止已经试过:
from what I have tried so far :
#!/usr/bin/perl
system("bash bashscript.sh");
击:
#!/bin/bash
echo "cdto codespace ..."
cd codetest
rm -rf cts
for sufix in a o exe ; do
echo ${sufix}
find . -depth -type f -name "*.${sufix}" -exec rm -f {} \;
done
我收到一个错误,当我执行perl脚本:
没有这样的文件或目录codeTEST
I am getting an error when I execute the perl script : No such file or directory codetest
附近意外的标记语法错误`做
syntax error near unexpected token `do
推荐答案
如果你只是想你运行脚本,你可以使用反引号或系统:
If you just want run you script you can use backticks or system:
$result = `/bin/bash /path/to/script`;
或
system("/bin/bash /path/to/script");
如果您的脚本生成的数据量的bug,
运行它的最好办法是使用开放+管:
If your script produces bug amount of data, the best way to run it is to use open + pipe:
if open(PIPE, "/bin/bash /path/to/script|") {
while(<PIPE>){
}
}
else {
# can't run the script
die "Can't run the script: $!";
}
这篇关于从perl脚本调用bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!