Note that there are some explanatory texts on larger screens.

plurals
  1. POin Java, why can't i pass an invocation string longer than 94 chars to Runtime.getRuntime().exec()?
    text
    copied!<p>I'm trying to invoke a .bat file from a java app. Seems simple, yet I'm having 2 problems and would really appreciate some advice: </p> <ol> <li><p>The code below fails to execute the bat file because the argument string is longer than 94 chars. if i use exactly 94 chars (by removing the trailing 'x' from the end of the <code>clientArgs</code> string) the bat file executes ok.<br> (same problem if i use the alternative invocation and pass the args as <code>String[]</code>)<br> anyway, i need to be able to pass much longer command strings (~150 chars)</p></li> <li><p>If I modify the <code>clientArgs</code> to not include the full file name but only the short name (since I'm specifying the working directory) I get: </p> <p><code>java.io.IOException: Cannot run program "client.bat" (in directory "C:\2\code\FlaFl\flafl-0.7-RC2"): CreateProcess error=2, The system cannot find the file specified</code></p></li> </ol> <p>here's the code: </p> <pre><code>public static void main(String[] args) { String CMD_FILE_NAME = "client.bat"; //cmd or bat - still limit'n is 94 chars String cmdFileFolder= "C:/2/code/FlaFl/flafl-0.7-RC2/"; File workingDir = new File(cmdFileFolder); String clientArgs = cmdFileFolder + CMD_FILE_NAME + " -host name12.mycompanyname3.com -app hive" + "123456789 34x"; //95 chars fails. remove the x to get it to work System.out.println("length of invoc str is "+clientArgs.length()); Process process=null; try { process = Runtime.getRuntime().exec(clientArgs,null,workingDir); } catch (IOException e) { System.out.println("exception "+e); } //sleep(2000); //if (process!=null) // process.destroy(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload