0

I have a Python3 script that needs to call a shell script with some parameters. When I call this shell script directly form the terminal - it works. The shell script call from terminal:

source $HW/scripts/gen.sh -top $TOP -proj opy_fem -clean

But when I try to call the shell script exactly the same way from Python 3 using os.system (or os.popen - same result), the shell script fails to run. Python call to the shell script:

os.system("source $HW/scripts/gen.sh -top $TOP -proj opy_fem -clean")

Get the next errors:

/project/users/alona/top_fabric_verif_env/logic/hw/scripts/gen.sh: line 18: syntax error near unexpected token `('
/project/users/alona/top_fabric_verif_env/logic/hw/scripts/gen.sh: line 18: `foreach i ( $* )'

Could you please shed light on why the same shell script fails to run from Python? Thank you for any help

1 Answer 1

1

foreach is a C-shell command. csh (and derivates like tcsh) are not standard system shells in Unix/Linux.

If you need to use a specific shell, for instance the C-shell:

os.system('/bin/csh -c "put the command here"')

This will execute the /bin/csh in the standard shell, but starting two shells instead of one creates an additional overhead. A better solution is:

subprocess.run(['/bin/csh', '-c', 'put the command here'])

Note that using the shell's source ... command does not make much sense when the shell exits after the command.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.