Skip to content
Advertisement

Passing command to the called script [closed]

I would like to call a script named openseessp and then pass "source test.tcl" argument to this script.

I tried with subprocess module but after it invoked openseessp it exits and then runs source test.tcl command. I need to run this without exiting the first (openseessp):

subprocess.run(['openseessp', 'source test.tcl'], shell=True, cwd=directoryJob)

Update: for the record, the code above works. The problem was related to openseessp. I changed openseessp (single processor version) to openseesmp (multiprocessor version) and it worked.

Advertisement

Answer

From the docs:

args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

That is, either pass a string with shell=True,

subprocess.run('openseessp source test.tcl', shell=True, cwd=directoryJob)

or pass a list (shell is False by default).

subprocess.run(['openseessp', 'source test.tcl'], cwd=directoryJob)
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement