formatting - How to execute a java command with interpolated arguments with Python's subprocess & Popen -


Trying to run Java commands from within Python on Windows, by using subprocess. Popen

First I have defined two strings:

  java_string = 'java -xmx1024m -classpath ;. ./ db2jcc.jar; ./ retainSdi.zip; ./jviews -chart.jar; ./jviews-framework.jar l2stats CRF1426 & gt; '+ Datetime.date.today (). Strftime ("% d /% m /% Y") + ' Html 'working_ir =' c: \\ user \\ IBM_ADMIN \\ Desktop \\ Weekly Report 2014 \\ "  

Then I tried to use the following subprocesses:

  Subprocess. Open ([java_string], cwd = work_dir) resulting in "FileNotFoundError: [WinError 2] system can not find the specified file"  

I edited java_string So that there is no Java command, such as:

  java_string = '-Xmx1024M -classpath ;. ./ db2jcc.jar; ./ retainSdi.zip; ./jviews-chart.jar; ./jviews-framework.jar l2stats CRF1426 & gt; 'Datetime.date.today (). Strftime ("% d /% m /% y") + '.html'   

And then Popen is called the same:

  subprocess .popen (['java', java_string], cwd = work_dir)   

resulting in

Invalid maximum pile size: - Xmx1024M-square path; ./ db2jcc.jar; ./ RetainSdi.z ip; ./jviews-chart.jar; ./jviews-framework.jar l2stats CRF1426 & gt; 21/04/2014 error: Java Virtual Machine could not be created.

that has at least one Java error (hence it is getting Java acc in% PAATH%, but Java is used to view the whole string What is to be done as an argument? I have no idea.

What is the correct formatting here? Anybody appreciated a lot of help!

You probably need to split the argument into a list, such as:

Unless otherwise stated, this Anu The order sequence is recommended to pass.

Instead of:

  subprocess.Popen (['Java', '-xmx 1024m -classpath.com.foo.Bar '] #Error (Invalid For Maximum Usage:  
  Subprocess .Popen ([' Java ',' -Xmx1024M ',' -classpath ',' ',' com.foo.Bar '] # Ok   

Also see Windows-specific.

Renewed : If you need features The shell, such as the redirect to the file using & gt; It is, then you must include the shell = T rue argument, for example:

  Upprkriya. As described in the comment of Popin ('echo eu & gt; Deleteme.txt', shell = true)   

or JF Sebastian (copied here for convenience), Specify the stdout argument:

  subprocess.call (['echo', 'foo'], stdout = open ('deleteme.txt', 'wb'))   

:

Passing a shell = true security can be if combined with untrusted input.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -