0

I am using python 2.7 on windows 7 64 bit machine. I am calling external application within python code as

os.startfile("D:\\dist\\NewProcess.exe")

This application(used py2exe for converting python script into an exe) uses two strings, which need to pass from parent process. So, how to pass these two strings, and how to get these strings in NewProcess.py file(may be by sys.argv argument)

imp
  • 1,967
  • 2
  • 28
  • 40

1 Answers1

2

You may try this:

import subprocess
import sys
try:
    retcode = subprocess.call("D:\\dist\\NewProcess.exe " + sys.argv[1] + " " + sys.argv[2], shell=True)
    if retcode < 0:
        print >>sys.stderr, "Child was terminated by signal", -retcode
    else:
        print >>sys.stderr, "Child returned", retcode
except OSError as e:
    print >>sys.stderr, "Execution failed:", e

In sys.argv[0] is the script name, and in sys.argv[1] ... [n] are script arguments. Example above is taken from subprocess module documentation https://docs.python.org/2/library/subprocess.html

Pavel Stárek
  • 959
  • 5
  • 6
  • `subprocess.check_call([r'D:\dist\NewProcess.exe'] + sys.argv[1:3])` – jfs Apr 08 '14 at 13:43
  • Note: negative `retcode` meaning a signal is Unix only. The path (and `py2exe`) suggests that OP uses Windows. – jfs Apr 08 '14 at 13:45