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)

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

subprocess.check_call([r'D:\dist\NewProcess.exe'] + sys.argv[1:3])
Note: negative retcode meaning a signal is Unix only. The path (and py2exe) suggests that OP uses Windows.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.