从批处理文件执行perl脚本

问题描述 投票:0回答:1

我有这个脚本shell,我想在Windows中执行它:

#!/bin/sh
# Create the structure of folders that will contain the result files
export perl_git_dir=path1
export OUTPUT_DIR=path2
mkdir $OUTPUT_DIR/output_perl

for FILE in `ls *.sh`
 do
    echo  "file is:"$FILE
    if [ -f "$FILE" ];then
        name=${FILE%.*}
        mkdir -p $OUTPUT_DIR/output_perl/"$name"
    fi;     
done

for entry in `ls *.sh`
 do
    if [ -f "$entry" ];then
        echo "enty is "$entry 
        echo "$entry" >> stdout.txt
        echo "$entry" >> stderr.txt
        ./$entry >> stdout.txt 2>> stderr.txt
    fi;     
done

我的结果是:创建目录然后在“stderr.txt”文件中出现此重复错误

mkdir: cannot create directory ‘path1/output_perl’: File exists
shell
1个回答
1
投票

代码似乎做了应该做的事情。在我的例子中,我用.sh替换了.pl,因为我没有任何脚本文件。注意:预期执行错误。

我只能假设这个问题太不完整而无法回答......

#!/bin/sh
_output_dir=path2

for f in *.pl; do
    basename=${f%.*}
    mkdir -p ${_output_dir}/output_perl/${basename}
    echo ${f} >>stdout.txt
    echo ${f} >>stderr.txt
    ./${f} >>stdout.txt 2>>stderr.txt
done

exit 0

测试运行:

$ sh dummy.sh 

$ cat stdout.txt 
dummy2.pl
dummy.pl
standard.pl
$ cat stderr.txt 
dummy2.pl
dummy.sh: line 9: ./dummy2.pl: Permission denied
dummy.pl
dummy.sh: line 9: ./dummy.pl: Permission denied
standard.pl
dummy.sh: line 9: ./standard.pl: Permission denied

$ ls path2/output_perl/
dummy  dummy2  standard
© www.soinside.com 2019 - 2024. All rights reserved.