How To Pass App Argument To Os.system()
Solution 1:
Per the open
man page, you have to pass --args
before arguments to the program:
--argsAll remaining arguments are passed to the opened application in the
argv parameterto main(). These arguments arenot opened or inter-
preted by the open tool.
As an aside, you may want to look into using subprocess
. Here's how the command looks like with subprocess
:
subprocess.check_call(['open', '-a', app, file])
No fiddling with string interpolation required.
Solution 2:
It is quite possible to submit the application's specific arguments to OS open
command.
The syntax to open
:
open -a /path/to/application/executable.file /filepath/to/the/file/to/open/with/app.ext
It appears it is OK to enclose both paths in double or single quotes such as:
open -a '/path/to/application/executable.file''/filepath/to/the/file/to/open/with/app.ext'
As Ned has mentioned flag --args
can be used to specify any Application's specific startup flags.
The App specific flags are placed after open
's --args
flag such as:
open -a /path/to/application/executable.file--args -proj
The problem is that the App specific flags (such as -proj
) will only be passed at the time the App is starting up. If it is already running the open -a
command will only open a file (if the file_to_be_opened is specified) but won't deliver the App's specific args. By other words the App is only able to receive its args at the time it starts.
There is -n
flag available to be used with open -a
command. When used open -a
will start as many instances of Apps as needed. Each of App instances will get the App args properly.
open -a '/path/to/application/executable.file''/filepath/to/the/file/to/open/with/app.ext -n --args -proj "SpecificToApp arg or command" '
It all translates if used with subprocess
:
subprocess.check_call(['open', '-a', app, file, '-n', '--args', '-proj', 'proj_flag_values'])
or simply pass it as a string arg to:
os.system(cmdString)
Post a Comment for "How To Pass App Argument To Os.system()"