| | |
put the Dos 's command into java program?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 8
Hi everyone,
Check out this thread. It has a very good example by Cheenu
http://www.daniweb.com/techtalkforums/thread27944.html
Richard West
Check out this thread. It has a very good example by Cheenu
http://www.daniweb.com/techtalkforums/thread27944.html
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
•
•
Join Date: May 2009
Posts: 1
Reputation:
Solved Threads: 0
Hi mmikkee,
I have used your code that you kindly put up and it works brilliantly when I use "ipconfig". However, I want to run a different command with arguments which runs when I navigate to the correct folder. So in the command line I run it as follows.
C:\> cd C:\Users\.....\bin.dbg
C:\Users\.....\bin.dbg>tesseract testImage.tif output
I just don't know how to get this to work using your code. I don't have much experience at all with java or command line to be honest so would greatly appreciate your help as its driving me mad!
Thanks
I have used your code that you kindly put up and it works brilliantly when I use "ipconfig". However, I want to run a different command with arguments which runs when I navigate to the correct folder. So in the command line I run it as follows.
C:\> cd C:\Users\.....\bin.dbg
C:\Users\.....\bin.dbg>tesseract testImage.tif output
I just don't know how to get this to work using your code. I don't have much experience at all with java or command line to be honest so would greatly appreciate your help as its driving me mad!
Thanks
•
•
•
•
Just because I feel like helping:
Java Syntax (Toggle Plain Text)
//CommandLine.java import java.util.*; import java.io.*; public abstract class CommandLine { public static void exec(String cmd) throws Exception { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(cmd.toString()); StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR"); StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT"); errorGobbler.start(); outputGobbler.start(); } public static void exec(String cmd, OutputStream output) throws Exception { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(cmd.toString()); StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR", output); StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT", output); errorGobbler.start(); outputGobbler.start(); } }Compile these two classes, then callJava Syntax (Toggle Plain Text)
//StreamGobbler.java import java.util.*; import java.io.*; class StreamGobbler extends Thread { InputStream is; String type; OutputStream os; StreamGobbler(InputStream is, String type) { this(is, type, null); } StreamGobbler(InputStream is, String type, OutputStream redirect) { this.is = is; this.type = type; this.os = redirect; } public void run() { try { PrintWriter pw = null; if (os != null) pw = new PrintWriter(os); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line=null; while ( (line = br.readLine()) != null) { if (pw != null) pw.println(line); System.out.println(line); } if (pw != null) pw.flush(); } catch (IOException ioe) { ioe.printStackTrace(); } } }
Replace ipconfig with whatever command you want to execute.Java Syntax (Toggle Plain Text)
CommandLine.exec("ipconfig");
•
•
Join Date: Oct 2009
Posts: 3
Reputation:
Solved Threads: 0
0
#18 Oct 15th, 2009
Is that possible to execute all the command available in cmd by a java program?
all that i know is there are .exe files corresponding to commands in windows>system32 folder, those are only executable by Runtime().exec command.what about other commands not having corresponding .exes?
Thanks.
![]() |
Similar Threads
- Selection Sort in java (Java)
- Running java command thru java program (Java)
- command prompt +java (Java)
Other Threads in the Java Forum
- Previous Thread: array stack infix and postfix
- Next Thread: using cardlayout in java
| Thread Tools | Search this Thread |
2dgraphics android api apple applet application arguments array arrays automation banking binary binarytree bluetooth capture chat chatprogramusingobjects class classes client code color component count database derby design eclipse eclipsedevelopment encryption error event exception fractal game givemetehcodez graphics gridlayout gui html ide if_statement image input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel julia keyword linux list loop macintosh map method methods midlethttpconnection mobile netbeans newbie object os print printing problem producer program programming project projectideas read recursion reference replaysolutions ria scanner screen server set size sms sort sourcelabs sql stop string swing threads transforms tree ui unicode validation windows






