0

I want to redirect the output of my jar in a file with python I have tried the following but it didn't work out

import sys
import subprocess

cmdargs = sys.argv
fname = str(cmdargs[1])
input = '../res/test/'+fname
output = '../res/res/'+fname
subprocess.Popen(['java', '-jar', '../res/chemTagger2.jar',input,'>',output]) 

the output is print in the console

1

1 Answer 1

1

You can redirect the subprocess.Popen stdout and stderr by using their parameters within the Popen command, as follows:

import sys
import subprocess

cmdargs = sys.argv
fname = str(cmdargs[1])
input = '../res/test/' + fname
output = '../res/res/' + fname

with open(output, 'a') as f_output:
    subprocess.Popen(['java', '-jar', '../res/chemTagger2.jar',input], stdout=f_output)
Sign up to request clarification or add additional context in comments.

Comments

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.