Skip to content
Advertisement

“Syntax error: Unterminated quoted string” error when calling a bash script from Python

I have a situation where, I need to call a bash script inside a python script which is in turn called inside another python script.

download-output-files.py:

JavaScript

watcher.py:

JavaScript

copy_output_file.sh:

JavaScript

When I run download-output-files.py , it calls watcher.py , which in turn calls copy_output_file.sh and below is the error I face:

JavaScript

When I run the same commands in Python shell, it runs bash script successfully. What am I missing?

Advertisement

Answer

It’s generally unwise to concatenate strings into shell commands. Try inserting print(cmd) before your os.system(cmd) calls to find out exactly what commands you’re trying to run, and I supect you’ll notice what the problem is (likely a file name with an apostrophe in it).

Try using subprocess.call(['python', 'watcher.py', i]) instead of os.system("python watcher.py "+i), and subprocess.call(['/copy_output_file.sh', node]) instead of os.system(cmd="./copy_output_file.sh "+node).

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement