![]() Print >sys.stderr, "Execution failed:", e Print >sys.stderr, "Child returned", retcode If retcode >sys.stderr, "Child was terminated by signal", -retcode Retcode = subprocess.call("open " filename, shell=True) If you need to be compatible all the way back to Python 2.4, you can use subprocess.call() and implement your own error checking: try: In Python 3.5 you can equivalently use the slightly more complex but also somewhat more versatile n(, check=True) You can also call them via subprocess module, but.įor Python 2.7 and newer, simply use subprocess.check_call() Windows: os.system("start " filename) where properly speaking filename should be escaped, too.MacOS/X: os.system("open " shlex.quote(filename)).Maybe see also python, windows : parsing command lines with shlex There is shlex.quote for Unix-like systems, but nothing really standard for Windows. A:\abc\def\a.txt), or else these need to be escaped. You can call them via os.system, which works, but.Įscaping: os.system only works with filenames that don't have any spaces or other shell metacharacters in the pathname (e.g. ![]() Here are considerations on which package to use: To call them from Python, you can either use subprocess module or os.system(). Open and start are command-interpreter things for Mac OS/X and Windows respectively, to do this. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |