0

I got a python file which is a code that I developed. During his execution I input from the keyboard several characters at different stages of the program itself. Also, during the execution, I need to close a notepad session which comes out when I execute into my program the command subprocess.call(["notepad",filename]). Having said that I would like to run this code several times with inputs which change according to the case and I was wondering if there is an automatic manner to do that. Assuming that my code is called 'mainfile.py' I tried the following command combinations:

import sys
sys.argv=['arg1']
execfile('mainfile.py')

and

import sys
import subprocess
subprocess.call([sys.executable,'mainfile.py','test'])

But it does not seem to work at least for the first argument. Also, as the second argument should be to close a notepad session, do you know how to pass this command?

1
  • In what way does it not work for the first argument? An what do you mean the second argument should be to close a notepad session? Commented Jul 17, 2015 at 12:03

2 Answers 2

0

Maybe have a look at this https://stackoverflow.com/a/20052978/4244387

It's not clear what you are trying to do though, I mean the result you want to accomplish seems to be just opening notepad for the sake of saving a file.

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

Comments

0

The subprocess.call() you have is the proper way to execute your script and pass it arguments.

As far as launching notepad goes, you could do something like this:

notepad = subprocess.Popen(['notepad', filename])
# do other stuff ...
notepad.terminate()  # terminate running session

3 Comments

Actually, the notepad problem is now fixed. I will keep investigating the usage of subprocess.call to pass arguments but at the moment I cannot see any calculation appearing on the screen
You mean your subprocess() call for mainfile.py produces no error messages?
Yes, and I am storing this information in another file which is placed in the same location as 'mainfile.py'

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.