简体   繁体   中英

os.system() and subprocess.call() behave differently

I have a script that launches Scribus with a specific file and automatically runs a Python script inside of Scribus.

I now want to pass further options to the Scribus script, but while doing that, I stumbled on a strange difference between os.system() (that I was using before) and subprocess.call() (that I'd like to use now, since the call is getting more complex).

The original command is:

os.system('scribus -g -py /home/ale/src/bin_etc/scribus-a6-to-a4-pdf.py -pa single -- funktionen.sla')

the new one is:

file = 'funktionen.sla'
arguments = ['-pa', 'single']

call(['scribus', '-g', '-py', '/home/ale/src/bin_etc/scribus-a6-to-a4-pdf.py'] + arguments + ['--', file])

While the first command works correctly (and the single command is recognized in the inner script), when running the new call() command, Scribus tells me that it could not find an open file.

To me, both commands look identical. Can anybody help spot the difference?

PS: As a complement, here is the documentation for running Scribus scripts from the command line:

https://wiki.scribus.net/canvas/Command_line_scripts

As I wrote in the comments to my question, I did not notice that the question had already the correct code.

The issue was that when you migrate code from os.system() to subprocess.call() , if you have an end of options ( -- ) you have to take care that you don't leave spaces around the two dashes: '-- ' is automatically trimmed by the shell (run by os.system() but not by subprocess.call() , which will pass along the options as they are and the final program will understand it as another option (named with a space) with the value of the file you intended to read.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM