Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is my code. As the comment says, works on Linux, fails on Windows (XP). AFAIK the problem with Windows is that cmd.exe is weird regarding it's parameters. For your specific sub-task you probably can get it to work by playing with quotes and maybe embedding the sub-task parameters in the subtask itself.</p> <pre><code>/** Execute an abritrary shell command. * returns the output as a String. * Works on Linux, fails on Windows, * not yet sure about OS X. */ public static String ExecuteCommand( final String Cmd ) { boolean DB = false ; if ( DB ) { Debug.Log( "*** Misc.ExecuteCommand() ***" ); Debug.Log( "--- Cmd", Cmd ); } String Output = ""; String ELabel = ""; String[] Command = new String[3]; if ( Misc.OSName().equals( "WINDOWS" ) ) { Command[0] = System.getenv( "ComSPec" ); Command[1] = "/C"; } else { Command[0] = "/bin/bash"; Command[1] = "-c"; } Command[2] = Cmd; if (DB ) { Debug.Log( "--- Command", Command ); } if ( Misc.OSName().equals( "WINDOWS" ) ) { Debug.Log( "This is WINDOWS; I give up" ); return ""; } try { ELabel = "new ProcessBuilder()"; ProcessBuilder pb = new ProcessBuilder( Command ); ELabel = "redirectErrorStream()"; pb.redirectErrorStream( true ); ELabel = "pb.start()"; Process p = pb.start(); ELabel = "p.getInputStream()"; InputStream pout = p.getInputStream(); ELabel = "p.waitFor()"; int ExitCode = p.waitFor(); int Avail; while ( true ) { ELabel = "pout.available()"; if ( pout.available() &lt;= 0 ) { break; } ELabel = "pout.read()"; char inch = (char) pout.read(); Output = Output + inch; } ELabel = "pout.close()"; pout.close(); } catch ( Exception e ) { Debug.Log( ELabel, e ); } if ( DB ) { Debug.Log( "--- Misc.ExecuteCommand() finished" ); } return Output; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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