rota90
rota90

Reputation: 259

execution perl script from batch file

I have this script shell and i want to execute it in 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

the result that I have is: the creation of the direcory then this repetitive error in "stderr.txt" file

mkdir: cannot create directory ‘path1/output_perl’: File exists

Upvotes: 0

Views: 597

Answers (1)

Stefan Becker
Stefan Becker

Reputation: 5952

Code seems to do what it is supposed to do. In my example I replaced .sh with .pl as I don't have any script files lying around. NOTE: the execution errors are expected.

I can only assume that the question is too incomplete to be answered...

#!/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

Test run:

$ 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

Upvotes: 1

Related Questions