<?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/"
xmlns:series="http://unfoldingneurons.com/"
> <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>Source of IT knowledge</description> <lastBuildDate>Thu, 09 Feb 2012 17:22:01 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>By: vishwa</title><link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-10101</link> <dc:creator>vishwa</dc:creator> <pubDate>Tue, 03 Jan 2012 06:35:43 +0000</pubDate> <guid
isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-10101</guid> <description>Hi ,
i want to save the file in wincvs using process and run command please give me sugestions</description> <content:encoded><![CDATA[<p>Hi ,</p><p>i want to save the file in wincvs using process and run command please give me sugestions</p> ]]></content:encoded> </item> <item><title>By: JavaGhost</title><link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-9870</link> <dc:creator>JavaGhost</dc:creator> <pubDate>Thu, 20 Oct 2011 19:03:16 +0000</pubDate> <guid
isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-9870</guid> <description>Hi Linglom,
I&#039;m trying to launch an exe application that accepts parameters from java. This application internally invokes Microsoft Visio. I need to run this application using a particular user. But RUNAS prompts for password which remains hidden. I tried writing the password to the stream but it threw &quot;java.io.IOException: The pipe is being closed&quot;
Here is the code:
List command = new ArrayList();
command.add(&quot;cmd.exe&quot;);
command.add(&quot;/C&quot;);
command.add(&quot;RUNAS&quot;);
command.add(&quot;/user:domain\\userName&quot;);
command.add(&quot;\&quot;D:\\someApp.exe arg1 arg2 arg3 arg4 arg5\&quot;&quot;);
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new File(&quot;D:\\&quot;));
builder.redirectErrorStream(true);
Process process = null;
String line;
OutputStream stdin = null;
InputStream stdout = null;
try {
process = builder.start();
stdin = process.getOutputStream();
stdout = process.getInputStream();
BufferedReader reader = new BufferedReader (new InputStreamReader(stdout));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));
while ((line = reader.readLine()) != null) {
System.out.println(&quot;[Stdout] &quot; + line);
}
writer.write(&quot;password&quot;);
writer.newLine();
writer.flush();
reader = new BufferedReader (new InputStreamReader(stdout));
while ((line = reader.readLine()) != null) {
System.out.println(&quot;[Stdout] &quot; + line);
}
reader.close();
int exit = process.waitFor();
System.out.println(exit);
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if (process != null) {
process.destroy();
}
}
It prints - [Stdout] Enter the password for domain\userName:
Then exception is thrown when flush() is called.
Please help me in this, it has bugged me since very long now.</description> <content:encoded><![CDATA[<p>Hi Linglom,<br
/> I&#8217;m trying to launch an exe application that accepts parameters from java. This application internally invokes Microsoft Visio. I need to run this application using a particular user. But RUNAS prompts for password which remains hidden. I tried writing the password to the stream but it threw &#8220;java.io.IOException: The pipe is being closed&#8221;<br
/> Here is the code:</p><p> List command = new ArrayList();<br
/> command.add(&#8220;cmd.exe&#8221;);<br
/> command.add(&#8220;/C&#8221;);<br
/> command.add(&#8220;RUNAS&#8221;);<br
/> command.add(&#8220;/user:domain\\userName&#8221;);<br
/> command.add(&#8220;\&#8221;D:\\someApp.exe arg1 arg2 arg3 arg4 arg5\&#8221;");<br
/> ProcessBuilder builder = new ProcessBuilder(command);<br
/> builder.directory(new File(&#8220;D:\\&#8221;));<br
/> builder.redirectErrorStream(true);<br
/> Process process = null;<br
/> String line;<br
/> OutputStream stdin = null;<br
/> InputStream stdout = null;<br
/> try {<br
/> process = builder.start();<br
/> stdin = process.getOutputStream();<br
/> stdout = process.getInputStream();<br
/> BufferedReader reader = new BufferedReader (new InputStreamReader(stdout));<br
/> BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));</p><p> while ((line = reader.readLine()) != null) {<br
/> System.out.println(&#8220;[Stdout] &#8221; + line);<br
/> }<br
/> writer.write(&#8220;password&#8221;);<br
/> writer.newLine();<br
/> writer.flush();<br
/> reader = new BufferedReader (new InputStreamReader(stdout));<br
/> while ((line = reader.readLine()) != null) {<br
/> System.out.println(&#8220;[Stdout] &#8221; + line);<br
/> }<br
/> reader.close();</p><p> int exit = process.waitFor();<br
/> System.out.println(exit);<br
/> } catch (IOException e) {<br
/> e.printStackTrace();<br
/> } catch (InterruptedException e) {<br
/> e.printStackTrace();<br
/> } finally {<br
/> if (process != null) {<br
/> process.destroy();<br
/> }<br
/> }</p><p>It prints &#8211; [Stdout] Enter the password for domain\userName:<br
/> Then exception is thrown when flush() is called.<br
/> Please help me in this, it has bugged me since very long now.</p> ]]></content:encoded> </item> <item><title>By: Achilles</title><link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-9414</link> <dc:creator>Achilles</dc:creator> <pubDate>Thu, 01 Sep 2011 18:12:58 +0000</pubDate> <guid
isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-9414</guid> <description>Hello, I need assistance with being able to run a command prompt through java. I have been working on it for the longest time and I am now stuck.
I am using Runtime but I am trying to use HJSplit.class
The only issue is that HJSplit can only properly run/execute is the class file is within the folder and the command line is at that location.
As in: C:\Documents\username\workspace\hjplsit
I press enter and type HJSplit -j Inputfile.txt
However I wish to bypass this by writing it in the code but I am stuck
I have Runtime.getRuntime().exec(&quot;cmd.exe /c start&quot;); what can I do to make is start at a specifc folder.
Also, If i just open the command promt and type
&quot;cd C:\Documents\username\workspace\hjplsit\HJSplit -j Inputfile&quot; I get a location not found</description> <content:encoded><![CDATA[<p>Hello, I need assistance with being able to run a command prompt through java. I have been working on it for the longest time and I am now stuck.</p><p>I am using Runtime but I am trying to use HJSplit.class</p><p>The only issue is that HJSplit can only properly run/execute is the class file is within the folder and the command line is at that location.</p><p>As in: C:\Documents\username\workspace\hjplsit<br
/> I press enter and type HJSplit -j Inputfile.txt</p><p>However I wish to bypass this by writing it in the code but I am stuck</p><p>I have Runtime.getRuntime().exec(&#8220;cmd.exe /c start&#8221;); what can I do to make is start at a specifc folder.<br
/> Also, If i just open the command promt and type<br
/> &#8220;cd C:\Documents\username\workspace\hjplsit\HJSplit -j Inputfile&#8221; I get a location not found</p> ]]></content:encoded> </item> <item><title>By: matt</title><link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-9123</link> <dc:creator>matt</dc:creator> <pubDate>Tue, 09 Aug 2011 17:39:40 +0000</pubDate> <guid
isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-9123</guid> <description>Thanks for the help.  The source code is &quot;money in the bank&quot;</description> <content:encoded><![CDATA[<p>Thanks for the help.  The source code is &#8220;money in the bank&#8221;</p> ]]></content:encoded> </item> <item><title>By: kevin</title><link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-8716</link> <dc:creator>kevin</dc:creator> <pubDate>Mon, 14 Mar 2011 10:20:15 +0000</pubDate> <guid
isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-8716</guid> <description>Disky, it sounds like you should just update your originally program to poll an array of directories, rather than running multiple instances.  This would be much more efficient and have a lot less overhead, why have multiple instances running when you can just have one?  All you would need to do is to run an extra loop to grab the extra parameters and parse them, (use a 2-D array), then put your poller inside of a loop and run it from i=0 to x where x is the length of the first index of your 2-d array.</description> <content:encoded><![CDATA[<p>Disky, it sounds like you should just update your originally program to poll an array of directories, rather than running multiple instances.  This would be much more efficient and have a lot less overhead, why have multiple instances running when you can just have one?  All you would need to do is to run an extra loop to grab the extra parameters and parse them, (use a 2-D array), then put your poller inside of a loop and run it from i=0 to x where x is the length of the first index of your 2-d array.</p> ]]></content:encoded> </item> <item><title>By: bella</title><link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-8450</link> <dc:creator>bella</dc:creator> <pubDate>Thu, 10 Feb 2011 02:31:43 +0000</pubDate> <guid
isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-8450</guid> <description>hi
how can i use java array and buffferdReader using into cdm..i dont know how to combined the code....please help me,tnx</description> <content:encoded><![CDATA[<p>hi<br
/> how can i use java array and buffferdReader using into cdm..i dont know how to combined the code&#8230;.please help me,tnx</p> ]]></content:encoded> </item> <item><title>By: disky</title><link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-8427</link> <dc:creator>disky</dc:creator> <pubDate>Thu, 03 Feb 2011 04:40:58 +0000</pubDate> <guid
isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-8427</guid> <description>Hi linglom, I am struggling with an issue. I have a java program compiled as several .java source files into a single jar called splitter.jar. I need to run it on a windows 2008 server so it runs continually polling a given directory for huge xml files and then splits them into smaller xml files. The java program works correctly and has been running for a few years. Now I need to invoke it from inside a java program ( that runs in a websphere server so when it is invoked it runs forever polling for files and then splitting them). Here is how the original splitter is invoked from a windows command prompt( some parameters are passed to it):
START javaw C:\Data\Splitter.jar C:\Data\Poller 20 YES xml
Now to invoke it from java code running in a websphere server, I use Runtime.exec(&quot;cmd /c START javaw .... xml&quot;). And it results in a process by name javaw.exe in the windows task manager, and works correctly. Is there a way I can make it show up as a task with a different name in the task manager ? The reason I want a different name is I need to run multiple splitter programs each polling a different directory, but all of them show up as several javaw.exe tasks in the windows task manager and I don&#039;t know which is polling which directory to kill them or recycle them individually. Please suggest. Thank you.</description> <content:encoded><![CDATA[<p>Hi linglom, I am struggling with an issue. I have a java program compiled as several .java source files into a single jar called splitter.jar. I need to run it on a windows 2008 server so it runs continually polling a given directory for huge xml files and then splits them into smaller xml files. The java program works correctly and has been running for a few years. Now I need to invoke it from inside a java program ( that runs in a websphere server so when it is invoked it runs forever polling for files and then splitting them). Here is how the original splitter is invoked from a windows command prompt( some parameters are passed to it):<br
/> START javaw C:\Data\Splitter.jar C:\Data\Poller 20 YES xml</p><p>Now to invoke it from java code running in a websphere server, I use Runtime.exec(&#8220;cmd /c START javaw &#8230;. xml&#8221;). And it results in a process by name javaw.exe in the windows task manager, and works correctly. Is there a way I can make it show up as a task with a different name in the task manager ? The reason I want a different name is I need to run multiple splitter programs each polling a different directory, but all of them show up as several javaw.exe tasks in the windows task manager and I don&#8217;t know which is polling which directory to kill them or recycle them individually. Please suggest. Thank you.</p> ]]></content:encoded> </item> <item><title>By: Jurgen</title><link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-8344</link> <dc:creator>Jurgen</dc:creator> <pubDate>Mon, 03 Jan 2011 14:03:30 +0000</pubDate> <guid
isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-8344</guid> <description>Actung, ich habe ein frage.
How can i execute a process from within a java Applet not a java Program??</description> <content:encoded><![CDATA[<p>Actung, ich habe ein frage.<br
/> How can i execute a process from within a java Applet not a java Program??</p> ]]></content:encoded> </item> <item><title>By: senioritta</title><link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-7348</link> <dc:creator>senioritta</dc:creator> <pubDate>Mon, 06 Dec 2010 18:55:03 +0000</pubDate> <guid
isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-7348</guid> <description>I also tried to create a Printwriter object and write the &quot;line&quot; variable using this object instead of System.out:
----------------
PrintWriter out = new PrintWriter(&quot;output.txt&quot;);
String line = null;
while ((line = input.readLine()) != null)
{
out.write(line);
}
-----------------
but it gave me an empty text file called output.txt!</description> <content:encoded><![CDATA[<p>I also tried to create a Printwriter object and write the &#8220;line&#8221; variable using this object instead of System.out:<br
/> &#8212;&#8212;&#8212;&#8212;&#8212;-<br
/> PrintWriter out = new PrintWriter(&#8220;output.txt&#8221;);<br
/> String line = null;<br
/> while ((line = input.readLine()) != null)<br
/> {<br
/> out.write(line);<br
/> }<br
/> &#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br
/> but it gave me an empty text file called output.txt!</p> ]]></content:encoded> </item> <item><title>By: senioritta</title><link>http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/comment-page-2/#comment-7347</link> <dc:creator>senioritta</dc:creator> <pubDate>Mon, 06 Dec 2010 18:50:35 +0000</pubDate> <guid
isPermaLink="false">http://www.linglom.com/2007/06/06/how-to-run-command-line-or-execute-external-application-from-java/#comment-7347</guid> <description>Thanks for the code, it is very helpful. but I have a small problem.
I need the output to appear in text file not on the CMD. I will describe the case in details:
I have a program called dlv.exe. I run it from command prompt as follows: dlv file1.dl and it produce the output on command prompt.
but if i run it as follows:
dlv file1.dl&gt;out.txt
then it produce the output in text file called out.txt
from this java code, I could run the first case correctly: dlv file1.txt and it is working fine
but the second &quot;dlv file1.txt&gt;out.txt&quot; is not producing the output to file.
Can anybody help?</description> <content:encoded><![CDATA[<p>Thanks for the code, it is very helpful. but I have a small problem.<br
/> I need the output to appear in text file not on the CMD. I will describe the case in details:</p><p>I have a program called dlv.exe. I run it from command prompt as follows: dlv file1.dl and it produce the output on command prompt.<br
/> but if i run it as follows:</p><p>dlv file1.dl&gt;out.txt</p><p>then it produce the output in text file called out.txt</p><p>from this java code, I could run the first case correctly: dlv file1.txt and it is working fine</p><p>but the second &#8220;dlv file1.txt&gt;out.txt&#8221; is not producing the output to file.</p><p>Can anybody help?</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: basic
Database Caching 4/20 queries in 0.112 seconds using disk: basic
Content Delivery Network via cdn.linglom.com/linglom

Served from: www.linglom.com @ 2012-02-10 10:59:06 -->
