Process running dos command copy... hangs!!
String cmdA = "cmd /C copy /Y " + dq + in + dq + " " + dq + out + dq;
// just a String of starting a dos cmd running copy...
Process p1 = Runtime.getRuntime().exec(cmdA);
p1.waitFor();
I'm pretty sure the command works perfectly fine in a dos window. The files I need to copy aren't big at all, but it always hangs after copying 3 files!! Since i used waitFor() to make sure the copying is finished before i continue, the whole thing will just hang there forever!!
I've also tried the xcopy command, but it's the same...
any help is appreciated!!
thx Kaj for your quick and helpful reply...
now i just use xcopy with /Q to not display so much information!!
but what's the good way to read both stdout and stderr at the same time and store them as useful informations!?
thx again : )
Similar Messages
-
Error while running DOS command in Java
Hi all,
I use "runtime" class to execute a DOS command "copy C:\\pathname\\*.* C:\\backupPathname\\". But I saw an error msg "CreateProcess: copy C:\pathname\*.* C:\backupPathname\ error=2".
I did create a folder C:\backupPathname\ before running the DOS command.
Pls help me all Java genius.I ended up writing a small 'c' program and pasing the command in to it from java. The problem seems to be that in dos, unlike unix, the copy command is not a program, rather the command is interpreted by the command.com program.
-
Is there a way to run dos commands on onther system?
Hi I have connected to a port of another system where windows is the operating system. So can I run dos commands on the other system through that network connection from my computer?
I'm not sure what you mean by "connected to a port of another system" . Which port using what software to which server?
-
How to run DOS command in Java environment?
Can i run DOS command in Java environment?
I did like this:
Runtime r = Runtime.getRuntime();
r.exec("cmd.exe");
r.exec("set classpath=%CLASSPATH%;.\\tmp")
but failed.
However if I run the java command, it runs successfully.
r.exec("javac Test.java");
r.exec("java Test");
how should I do so that i can run the DOS commands metioned above in Java Environment?
thanks a lot.Have a look at http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
This may help. I wonder if this is ok ?
Runtime r= Runtime.getRuntime();
r.exec("cmd.exe /C set classpath=%CLASSPATH%;.\\tmp\""); -
Hi ,
I would appreciate if anyone could tell me how to run DOS command such as "del" using JAVA language .Thank you.<steps onto soapbox>
Surely for something like 'del' we should be advocating a non-OS specific method so we don't lose sight of Java's cross platform abilities.
If it has to run an OS specific thing fine, but please look for a non OS specific solution first.
<steps off soapbox> -
Is it possible to run dos-command's in java?
I have a small security problem. I have a dos-based java prog. with login at the start og the program, but I have problems hiding the password. I have managed to hide the password when it is typed, but when you press enter and get to the next menu, it is only to press the up-key, and dos recover the last typed sentence. (The password...) I have been able to fine the dos-command "doskey /reinstall", which will clear the memory, but I haven't been able to implemet this in my java-prog.
Any tips/trics are appreciated.I have a small security problem. I have a dos-based
java prog. with login at the start og the program, but
I have problems hiding the password. I have managed to
hide the password when it is typed, but when you press
enter and get to the next menu, it is only to press
the up-key, and dos recover the last typed sentence.
(The password...) I have been able to fine the
dos-command "doskey /reinstall", which will clear the
memory, but I haven't been able to implemet this in my
java-prog.
I doubt that calling that in your program would help.
doskey is specific to the process. Running it by any means in java means that a new process will exist. You can verify this by open two console windows and running doskey in both. Nothing that you do in one will be reflected in the other.
I don't think your problem is a program problem. That means that it should not be solved by software but rather by management. For example you certainly wouldn't expect your program to make sure that someone wasn't standing behind the user when they typed their password right? And what if someone installs a key grabber on the computer? In that case any program, yours included, would have all the key presses logged to a file.
Alternatively if you might be able to solve it with one of the following...
- Recode the application to use a GUI. If there is no console the doskey isn't going to get anything.
- Write some JNI that bypasses the java input handling. If you handle the input directly then you can turn off echo
- Inspect the java source code for the VM. There might be a hidden method to turn echo off. Alternatively you can find the code responsible for this, modify them, and use them with the bootclass option to replace the ones in the VM. This solution is not distributable. And it might not be possible solely using java. -
Problem while running dos command from java program
Dear friends,
I need to terminate a running jar file from my java program which is running in the windows os.
For that i have an dos command to find process id of java program and kill by using tskill command.
Command to find process id is,
wmic /output:ProcessList.txt process where "name='java.exe'" get commandline,processid
This command gives the ProcessList.txt file and it contains the processid. I have to read this file to find the processid.
when i execute this command in dos prompt, it gives the processid in the ProcessList.txt file. But when i execute the same command in java program it keeps running mode only.
Code to run this command is,
public class KillProcess {
public static void main(String args[]) {
KillProcess kProcess = new KillProcess();
kProcess.getRunningProcess();
kProcess = new KillProcess();
kProcess.readProcessFile();
public void getRunningProcess() {
String cmd = "wmic /output:ProcessList.txt process where \"name='java.exe'\" get commandline,processid";
try {
Runtime run = Runtime.getRuntime();
Process process = run.exec(cmd);
int i = process.waitFor();
String s = null;
if(i==0) {
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(process.getInputStream()));
while ((s = stdInput.readLine()) != null) {
System.out.println("--> "+s);
} else {
BufferedReader stdError = new BufferedReader(new
InputStreamReader(process.getErrorStream()));
while ((s = stdError.readLine()) != null) {
System.out.println("====> "+ s);
System.out.println("Running process End....");
} catch(Exception e) {
e.printStackTrace();
public String readProcessFile() {
System.out.println("Read Process File...");
File file = null;
FileInputStream fis = null;
BufferedReader br = null;
String pixieLoc = "";
try {
file = new File("ProcessList.txt");
if (file.exists() && file.length() > 0) {
fis = new FileInputStream(file);
br = new BufferedReader(new InputStreamReader(fis, "UTF-16"));
String line;
while((line = br.readLine()) != null) {
System.out.println(line);
} else {
System.out.println("No such file");
} catch (Exception e) {
e.printStackTrace();
return pixieLoc;
} when i remove the process.waitFor(), then while reading the ProcessList.txt file, it says "No such file".
if i give process.waitFor(), then it's in running mode and program is not completed.
Colud anyone please tell me how to handle this situation?
or Is there anyother way to kill the one running process in windows from java program?
Thanks in advance,
SathishHi masijade,
The modified code is,
class StreamGobbler extends Thread
InputStream is;
String type;
StreamGobbler(InputStream is, String type)
this.is = is;
this.type = type;
public void run()
try
InputStreamReader isr = new InputStreamReader(is, "UTF-16");
BufferedReader br = new BufferedReader(isr);
String line=null;
while ( (line = br.readLine()) != null)
System.out.println(type + ">" + line);
} catch (IOException ioe)
ioe.printStackTrace();
public class GoodWindowsExec
public static void main(String args[])
try
String osName = System.getProperty("os.name" );
String[] cmd = new String[3];
if( osName.equals( "Windows 95" ) )
cmd[0] = "command.com" ;
cmd[1] = "/C" ;
cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
} else {
cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
Runtime rt = Runtime.getRuntime();
System.out.println("Execing " + cmd[0] + " " + cmd[1]
+ " " + cmd[2]);
Process proc = rt.exec(cmd);
System.out.println("Executing.......");
// any error message?
StreamGobbler errorGobbler = new
StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new
StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
// any error???
int exitVal = proc.waitFor();
System.out.println("ExitValue: " + exitVal);
} catch (Throwable t)
t.printStackTrace();
}when i execute the above code, i got output as,
Execing cmd.exe /C wmic process where "name='java.exe'" get commandline,processid
and keeps in running mode only.
If i execute the same command in dos prompt,
CommandLine
ProcessId
java -classpath ./../lib/StartApp.jar;./../lib; com.abc.middle.startapp.StartAPP 2468
If i modify the command as,
cmd.exe /C wmic process where "name='java.exe'" get commandline,processid > 123.txt
and keeps in running mode only.
If i open the file when program in running mode, no contents in that file.
If i terminte the program and if i open the file, then i find the processid in that file.
Can you help me to solve this issue? -
Running Dos Command using Java
How do i run a particular Dos command using a simple java class?
Process process = Runtime.getRuntime().exec( ... );
Search the forum. There are plenty of examples. -
Doesn't it get very old, same question about running dos command?
To everyone who is tooo lazy to search.
Process p = Runtime.getRuntime().exec("progname arg1 arg2");
What a wast of everyone's time responding to the same question on how to run a dos command.I think you'll find it's
Runtime.getRuntime().exec(new String[]{"progname", "arg1", "arg2"}); -
May I ask how I should write if I want to execute a dos command in java? The command is :
"C:\Program Files\Real\realproducer\rmeditor -i abc.rm -d abc.txt". Should I use array?
Thanks!why an array ?
String command = "C:\\Program Files\\Real\\realproducer\\rmeditor -i abc.rm -d abc.txt";
Process p = Runtime.getRuntime().exec( command );what about the seach function on the left side ? ;-)
tobias -
How to run dos command on java
would java run the dos command ?
if yes ~would you mind give me some example~please~..or just use:
Runtime.getRuntime().exec("cmd /c commandyouwanttouse");
Hope it works! -
Is possible to run a dos command by an AIR application and
obtain the result? For example: can I launch "iireset /status" and
obtain the status of iis?
Grazie!You need to write a small Java Socket Listener, and you also
need to create the Socket in you AIR Application. Before starting
your AIR Application you need to start the SocketListener which
sits listening to the incoming connection from the AIR Application.
But you should use the same port at both the ends(Java and
AIR Application end).
Regards,
Code. -
HOW DO I RUN DOS COMMANDS ON JAVA
I SWEAR, I'LL PAY YA IF YOU HELP ME!!!
Hi, this is the thing:
have you ever run the "time" command on a DOS console?? if you have, you know that it shows the current time, and lets you set a new time.
well, i need to make a java program to open a DOS console and execute the command, and making it able to write in information on the console so it sets a new time.
MY PURPOSE IS NOT JUST WATCHING THE CURRENT TIME!! so please don't tell me to use System.getCurrentTimeMillis() or something like that; i explicitly need to run that DOS command. what's the Java code to do it??
thank you!! and please attach your account # so you get a $50 deposit by the end of the week
thank you!!Thanks a lot, you all guys, but i don't know what's with this thing.... it always throws an IOException, with the following exception stack trace:
java.io.IOException: CreateProcess: temp.bat error=0
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:63)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:550)
at java.lang.Runtime.exec(Runtime.java:416)
at java.lang.Runtime.exec(Runtime.java:358)
at java.lang.Runtime.exec(Runtime.java:322)
at Tarea.main(Tarea.java:15)and it will come out the same shit over and over. The above case was thrown by the line Runtime.getRuntime().exec("temp.bat") where temp.bat is a file where the only thing written in it is the word "time". and you can change the string parameter of the method exec, and thats what will change in the stack trace above.
I also tried "cmd", "command", and "command.com". With the last one, it opens the command.com application but it freezes and does nothing. With the other two, appears the same old shit from above.
Please help me!!
Thank you... -
Hi,
I am trying to run few dos commands through java using Runtime.exec("command") but I am getting following error
commmand is cd D:\CodeMerge\A\
java.io.IOException: CreateProcess: cd.. error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Unknown Source)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at createDirectory.main(createDirectory.java:24)
Basically what I am looking for is this:
1) My program is in D:\Amit\RM
2) I want to get out to D:\ go to CodeMerge\A\.
3) Create folder with curretn date as name of the folder
Hence I am doing
rTime.exec("cd../..");
rTime.exec("cd D:\CodeMerge\A\");
rTime.exec("mkdir "+date);
Can anybody tell me why I am getting this error
JountyDoublepost.
http://forum.java.sun.com/thread.jspa?threadID=635077&tstart=0 -
hi all,
i am running this command at command prompt
like below
java filename argument.
ex: java validateuser user1
it works fine at command prompt. and the same command i want to run in jsp
so i tried like this
Runtime x = Runtime.getRuntime().exec("java validateuser user1");
whats happenning here is it just opening command promot of java.exe but its not running validateuser.
any help will be greatly appreciated.
advance thanks.why on earth are you trying to run java.exe on the command line through JSP?i think you misunderstand my question.
i am not trying to run java.exe on through jsp.
I am trying to run a validateuser user1 in jsp .
Note:validateuser is a java file which take one argument.here in my scnerio user1 is the argument.
Maybe you are looking for
-
My 06' Macbook Pro crashed with vertical, green pixelated lines and now will not advance past the turn-on screen with the apple filled with green lines as well. Then, it says to hold down the power button to restart. I have tried several times to get
-
Hi all, My department got new server with XI installed. As our IT-support team is unavailable at the moment, I was told to configure installed XI server. And now I'm completely embarrassed - I studied to use XI, but not to configure the system. Can a
-
Understanding logminer results -- inserting row into table with CLOB field
In using log miner I have noticed that inserts into rows that contain a CLOB (I assume this applies to other LOB type fields as well, have only tested with CLOB so far) field are actually recorded as two DML entries. --the first entry is the insert o
-
How do I recover a book that has disappeared from my iBooks Library?
I am halfway through one of the storm of swords books and I am now all of a sudden getting the error message "This book cannot be found. The IBook resource cannot be located". I have gone to "purchased" history and I can't redownload for some reason
-
Reinstalling through Creative Cloud, after failed installation?
How does that work? I got a message that I have to uninstall and then reinstall me trail version of InDesign. Opening the Creative Cloud does not help at all. Here I am status: installed. So now, I cannot reinstall as I was told to. I need assistance