Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Expanding on FatalError's suggestion with an example. </p> <p>One additional benefit of using <code>subprocessing</code> rather than <code>os.system</code> is that it uses the same syntax cross-platform (<code>os.system</code> on Windows requires a "start" at the beginning, whereas OS X requires and "open". Not a huge deal, but one less thing to remember). </p> <h2>Opening a file with <code>subprocess.call</code>.</h2> <p>All you need to do to launch a program is call <code>subprocess.call()</code> and lass in a <code>list</code> of arguments where the first is the path to the program, and the rest are additional arguments that you want to supply to the program you're launching. </p> <p>For instance, to launch Notepad.exe</p> <pre><code>import subprocess import os path_to_notepad = 'C:\\Windows\\System32\\notepad.exe' path_to_file = 'C:\\Users\\Desktop\\hello.txt' subprocess.call([path_to_notepad, path_to_file]) </code></pre> <p>Passing multiple arguments and paths is equally as simple. Just add additional items to the list. </p> <hr> <h3>Launching with multiple arguments</h3> <p>This, for example, launches a JAR file using a specific copy of the Java runtime environment. </p> <pre><code>import subprocess import os current_path = os.getcwd() subprocess.call([current_path + '/contents/home/bin/java', # Param 1 '-jar', #Param2 current_path + '/Whoo.jar']) #param3 </code></pre> <p>Argument 1 targets the program I want to launch. Argument2 supplies an argument <em>to</em> that program telling it that it's going to run a JAR, and finally Argument3 tells the target program where to find the file to open. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload