<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to run command-line or execute external application from Java</title>
	<atom:link href="http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/</link>
	<description>Just another IT weblog</description>
	<lastBuildDate>Fri, 12 Mar 2010 18:21:20 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: arnie</title>
		<link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-6168</link>
		<dc:creator>arnie</dc:creator>
		<pubDate>Fri, 12 Mar 2010 03:19:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-6168</guid>
		<description>Hi linglom ,


I know this cmd but it doesn&#039;t give you access if the &quot;Administrator&quot; account is not password protected and if it is or if you try the same cmd with other administrator account which supports a password , a new cmd prompt will appear but actually it doesn&#039;t run as administrator, so this cmd doesn&#039;t change anything (if you tried it you know what I m talking about)

But thanks for your interest!</description>
		<content:encoded><![CDATA[<p>Hi linglom ,</p>
<p>I know this cmd but it doesn&#8217;t give you access if the &#8220;Administrator&#8221; account is not password protected and if it is or if you try the same cmd with other administrator account which supports a password , a new cmd prompt will appear but actually it doesn&#8217;t run as administrator, so this cmd doesn&#8217;t change anything (if you tried it you know what I m talking about)</p>
<p>But thanks for your interest!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: linglom</title>
		<link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-6167</link>
		<dc:creator>linglom</dc:creator>
		<pubDate>Fri, 12 Mar 2010 02:24:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-6167</guid>
		<description>Hi, Arnie

You can use runas command to run the command prompt as administrator but you need to specify password after run the command:

&quot;runas /user:Administrator cmd&quot;

Reference: &lt;a href=&quot;http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Runas&lt;/a&gt;</description>
		<content:encoded><![CDATA[<p>Hi, Arnie</p>
<p>You can use runas command to run the command prompt as administrator but you need to specify password after run the command:</p>
<p>&#8220;runas /user:Administrator cmd&#8221;</p>
<p>Reference: <a href="http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/runas.mspx?mfr=true" target="_blank" rel="nofollow">Runas</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anup</title>
		<link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-6159</link>
		<dc:creator>Anup</dc:creator>
		<pubDate>Wed, 10 Mar 2010 15:43:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-6159</guid>
		<description>THanks for this article... Saved me a lot of time while making my Java app.</description>
		<content:encoded><![CDATA[<p>THanks for this article&#8230; Saved me a lot of time while making my Java app.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: arnie</title>
		<link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-6155</link>
		<dc:creator>arnie</dc:creator>
		<pubDate>Mon, 08 Mar 2010 17:20:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-6155</guid>
		<description>Hi,

does anyone know how to run a cmd prompt with administrative privilleges through a java program?

Thanks in advance!</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>does anyone know how to run a cmd prompt with administrative privilleges through a java program?</p>
<p>Thanks in advance!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabor</title>
		<link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-6141</link>
		<dc:creator>Gabor</dc:creator>
		<pubDate>Fri, 05 Mar 2010 14:50:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-6141</guid>
		<description>Hi,
I&#039;ve found a solution in the meanwhile here:

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1

But thanks anyway for the great article &amp; thread!</description>
		<content:encoded><![CDATA[<p>Hi,<br />
I&#8217;ve found a solution in the meanwhile here:</p>
<p><a href="http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1" rel="nofollow">http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html?page=1</a></p>
<p>But thanks anyway for the great article &amp; thread!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gabor</title>
		<link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-6140</link>
		<dc:creator>Gabor</dc:creator>
		<pubDate>Fri, 05 Mar 2010 13:18:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-6140</guid>
		<description>Hi linglom,
I have following code:

String cm = &quot; rmdir /q /s &quot; + dir;
Process process = Runtime.getRuntime().exec(&quot;cmd /c &quot; + cm);
int exitVal = process.waitFor();

If I try to run it from Eclipse, it executes well.
If I generate a (fat) jar from it, and start it from the 
DOS window, it hangs forever.

Do you have any hint?

Cheers / Gabor</description>
		<content:encoded><![CDATA[<p>Hi linglom,<br />
I have following code:</p>
<p>String cm = &#8221; rmdir /q /s &#8221; + dir;<br />
Process process = Runtime.getRuntime().exec(&#8220;cmd /c &#8221; + cm);<br />
int exitVal = process.waitFor();</p>
<p>If I try to run it from Eclipse, it executes well.<br />
If I generate a (fat) jar from it, and start it from the<br />
DOS window, it hangs forever.</p>
<p>Do you have any hint?</p>
<p>Cheers / Gabor</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: linglom</title>
		<link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-6130</link>
		<dc:creator>linglom</dc:creator>
		<pubDate>Thu, 04 Mar 2010 15:06:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-6130</guid>
		<description>Hi, Aravin

You should use Java applet if you want to develop Java application on web.</description>
		<content:encoded><![CDATA[<p>Hi, Aravin</p>
<p>You should use Java applet if you want to develop Java application on web.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: aravin</title>
		<link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-1/#comment-6116</link>
		<dc:creator>aravin</dc:creator>
		<pubDate>Tue, 02 Mar 2010 04:18:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-6116</guid>
		<description>Helo, i&#039;m beginner in java. How to run this coding in xml, bacauce i want to create web page that can execute this code. Anybody can give idea about this.</description>
		<content:encoded><![CDATA[<p>Helo, i&#8217;m beginner in java. How to run this coding in xml, bacauce i want to create web page that can execute this code. Anybody can give idea about this.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe Negron NYC</title>
		<link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-1/#comment-5614</link>
		<dc:creator>Joe Negron NYC</dc:creator>
		<pubDate>Fri, 05 Feb 2010 07:33:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-5614</guid>
		<description>Excellent and very helpful article, Linglom. Thank you for posting it. For me the comments may be even more helpful... 

I have a similar problem as Kevin (above) but some of the os-agnostic applications I am launcing do not have a /q or &quot;quite mode&quot;. Is there any way to create a 2-way interactive process or thread?

I have the following: 
&lt;code&gt;
String line=&quot;&quot;;
BufferedReader br;
br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer s2 = new StringBuffer();
Runtime oShell = Runtime.getRuntime();
String oSysName = System.getProperty(&quot;os.name&quot; );
if(oSysName.toUpperCase().startsWith(&quot;WIN&quot;)) { 
  // We need to make this OS Agnostic 
  line = &quot;cmd.exe /c &quot;+getPath(sCommand)+&quot;.cmd&quot;; // Shell Out to Win32
  } else { line = &quot;/bin/sh -c &quot;+getPath(sCommand); } // Shell to UNIX, Linux or MAC   
String args[] = line.split(&quot;[ \t]+&quot;);  // tokenize the commandLine into an array for exec()     
System.out.println(&quot;\n SHELL&gt; Type any additional parameters, end with ^D (UNIX) or ^Z (Win32) + [Enter] \n\n&quot;);
do {
  line = br.readLine();
  if (line != null) { args = addArrayNode (args, line); }
 } while (line != null);
System.out.print(&quot; SHELL&gt; Executing Command, Please Wait... &quot;);
System.out.print(&quot;\n\n The Following String is being sent to &quot;+oSysName+ &quot; for processing:\n\t&quot;+Arrays.toString(args));
Process oProc = oShell.exec(args);  //Process Launcher
// create reader to get errors as a character stream from the child process...
final BufferedReader errorHandler =
  new BufferedReader(new InputStreamReader(oProc.getErrorStream()));

// create reader to get standard output as a character stream from child process...
final BufferedReader outputHandler = 
  new BufferedReader(new InputStreamReader(oProc.getInputStream()));
&lt;/code&gt;

Then I launch threads to capture and display the output. such as: 

&lt;code&gt;
//Get and display the standard output produced by the child process...(for non-ERRORs)
Thread stdoutThread = new Thread() {
  public void run() {  
    try { int l; String line;
      for(l = 0; (line = outputHandler.readLine()) != null; ) {
         if (line.length() &gt; 0) { l++; outputLines.addElement(line); }
         System.out.println(line);
       }
     if (l &gt;0) System.out.print(&quot;\n\nRead &quot; + l + &quot; lines (above) from stdout.&quot;);
     outputHandler.close();
   } catch (IOException ie) { System.out.println(&quot;SHELL&gt; IO exception on stdout: &quot; + ie); }
  }
 };//end-sddoutThread-def
&lt;/code&gt;

I&#039;m having a hard time getting my head around the (interactive scenario&#039;s) thread handler. How do I know if it needs a response? Which thread should I watch? Both? Maybe use: getOutputStream ??? 

not sure if my code snippits will be formatted properly, but any help would be greatly appreciated..

Joe</description>
		<content:encoded><![CDATA[<p>Excellent and very helpful article, Linglom. Thank you for posting it. For me the comments may be even more helpful&#8230; </p>
<p>I have a similar problem as Kevin (above) but some of the os-agnostic applications I am launcing do not have a /q or &#8220;quite mode&#8221;. Is there any way to create a 2-way interactive process or thread?</p>
<p>I have the following:<br />
<code><br />
String line="";<br />
BufferedReader br;<br />
br = new BufferedReader(new InputStreamReader(System.in));<br />
StringBuffer s2 = new StringBuffer();<br />
Runtime oShell = Runtime.getRuntime();<br />
String oSysName = System.getProperty("os.name" );<br />
if(oSysName.toUpperCase().startsWith("WIN")) {<br />
  // We need to make this OS Agnostic<br />
  line = "cmd.exe /c "+getPath(sCommand)+".cmd"; // Shell Out to Win32<br />
  } else { line = "/bin/sh -c "+getPath(sCommand); } // Shell to UNIX, Linux or MAC<br />
String args[] = line.split("[ \t]+");  // tokenize the commandLine into an array for exec()<br />
System.out.println("\n SHELL&gt; Type any additional parameters, end with ^D (UNIX) or ^Z (Win32) + [Enter] \n\n");<br />
do {<br />
  line = br.readLine();<br />
  if (line != null) { args = addArrayNode (args, line); }<br />
 } while (line != null);<br />
System.out.print(" SHELL&gt; Executing Command, Please Wait... ");<br />
System.out.print("\n\n The Following String is being sent to "+oSysName+ " for processing:\n\t"+Arrays.toString(args));<br />
Process oProc = oShell.exec(args);  //Process Launcher<br />
// create reader to get errors as a character stream from the child process...<br />
final BufferedReader errorHandler =<br />
  new BufferedReader(new InputStreamReader(oProc.getErrorStream()));</p>
<p>// create reader to get standard output as a character stream from child process...<br />
final BufferedReader outputHandler =<br />
  new BufferedReader(new InputStreamReader(oProc.getInputStream()));<br />
</code></p>
<p>Then I launch threads to capture and display the output. such as: </p>
<p><code><br />
//Get and display the standard output produced by the child process...(for non-ERRORs)<br />
Thread stdoutThread = new Thread() {<br />
  public void run() {<br />
    try { int l; String line;<br />
      for(l = 0; (line = outputHandler.readLine()) != null; ) {<br />
         if (line.length() &gt; 0) { l++; outputLines.addElement(line); }<br />
         System.out.println(line);<br />
       }<br />
     if (l &gt;0) System.out.print("\n\nRead " + l + " lines (above) from stdout.");<br />
     outputHandler.close();<br />
   } catch (IOException ie) { System.out.println("SHELL&gt; IO exception on stdout: " + ie); }<br />
  }<br />
 };//end-sddoutThread-def<br />
</code></p>
<p>I&#8217;m having a hard time getting my head around the (interactive scenario&#8217;s) thread handler. How do I know if it needs a response? Which thread should I watch? Both? Maybe use: getOutputStream ??? </p>
<p>not sure if my code snippits will be formatted properly, but any help would be greatly appreciated..</p>
<p>Joe</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin H. Hamstad</title>
		<link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-1/#comment-5200</link>
		<dc:creator>Martin H. Hamstad</dc:creator>
		<pubDate>Fri, 22 Jan 2010 07:15:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-5200</guid>
		<description>Hi
This works fine for jobs that finish and give it&#039;s feedback immidiately and then closes. But how shall I do it for jobs that run &quot;for a while&quot;, for example a &quot;tar -tvf&quot; to tape drive ?</description>
		<content:encoded><![CDATA[<p>Hi<br />
This works fine for jobs that finish and give it&#8217;s feedback immidiately and then closes. But how shall I do it for jobs that run &#8220;for a while&#8221;, for example a &#8220;tar -tvf&#8221; to tape drive ?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
