Execute DOS command in current window!
All:
Here is my code :
import java.io.*;
public class BuildScript {
public static void main ( String[] args ) {
String[] command = {"C:\\winnt\\system32\\cmd.exe", "cls"};
try {
Process process = Runtime.getRuntime().exec ( command );
process.waitFor();
} catch ( InterruptedException e ) {
e.printStackTrace();
System.exit(-1);
} catch ( IOException e ) {
e.printStackTrace();
System.exit(-1);
System.out.println ( "DONE!" );
I just want to exeute some simple DOS command from Java application. And then I run this code, it hangs there for ever. I comments out "process.waitFor()", then it print out the "DONE" however it seems that it just open another console and clear that one and exit. For the main console I start my code, nothing happened.
Can anyone help me out how to execute the dos command in current console window.
Thanks
Can anyone help me out how to execute the dos command in current console window.Sorry to say but there is no way to do that.
The best way to clear the screen is to print a few hundred newlines.
Trust me, this is a frequently asked question.
Similar Messages
-
Execute dos commands through java
Hi,
Im trying to execute dos commands through java like
try {
java.lang.Runtime.getRuntime().exec("cmd /c cls");
}catch(IOException e){
System.out.println(e.getMessage());
}Not sure if its possible? however
open notepad would work
try {
java.lang.Runtime.getRuntime().exec("notepad");
}catch(IOException e){
System.out.println(e.getMessage());
}Im trying to execute a cls commands to clear screen but without luck.The question is, which shell do you want to clear?
I don't really know, but it could be that Runtime.exec executes its command in a new shell window... -
How to execute dos command in Java program?
In Perl, it has System(command) to call dos command.
Does java have this thing?
or any other way to execute dos command in java program?
Because i must call javacto compile a file when the user inputed a java file name.Look in the Runtime class, it is implemented using the Singleton design pattern so you have to use the static method getRuntime to get its only instance, on that instance you can invoke methods like
exec(String command) that will execute that command in a dos shell.
Regards,
Gerrit. -
hi experts ,
i need to execute DOS command from SAP .
earlier we have 'GUI_EXEC' WS_EXECUTE , 'WS_DOWNLOAD' etc which are Obsolete now.
as we are using ECC6.0. kindly guide how to do this.
best regards,
RahulTry out...
DSVAS_DOC_WS_EXECUTE_50
or
CL_GUI_FRONTEND_SERVICES=>EXECUTE
<b><REMOVED BY MODERATOR></b>
Thanks & Regards
ilesh 24x7
Message was edited by:
Alvaro Tejada Galindo -
How to execute Dos Command 'Pause' from Java ?
How to execute Dos Command 'Pause' from Java ?
I have read the article in javaworld for Runtime.exec() anomalies.
Can someone please give an insight on this?Thanks Buddy!
That was very useful. Even though its a simple
solution, I never thought about that.Bullshit! Reread reply #7 of http://forum.java.sun.com/thread.jspa?threadID=780193 -
EXECUTE DOS COMMANDS WITH JAVA
I'm new to java and I want to execute dos commands by java
can someone help me by by anyway?
like tell me the packages or methods I need
or give me links to sites?
thanksNo Arguments:
try {
// Execute a command without arguments
String command = "ls";
Process child = Runtime.getRuntime().exec(command);
// Execute a command with an argument
command = "ls /tmp";
child = Runtime.getRuntime().exec(command);
} catch (IOException e) {
}With Arguments:
try {
// Execute a command with an argument that contains a space
String[] commands = new String[]{"grep", "hello world", "/tmp/f.txt"};
commands = new String[]{"grep", "hello world", "c:\\Documents and Settings\\f.txt"};
Process child = Runtime.getRuntime().exec(commands);
} catch (IOException e) {
} -
Can we execute DOS Commands from a Java Application
I just want to know whether we can execute DOS Commands from a Java Application.
Thanks.hi,
try this:
Runtime.getRuntime().exec("cmd /c start abc.bat");
andi -
How to execute DOS command in Java?
I want to execute a dos command in Java,such as execute test.bat command? How to realize it?
Thanks in advance!http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
I found this article really useful in solving this. Hope it helps.
Cheers,
John -
Execute DOS command inside java
I have a java program that reads each new user from an inputfile and writes that same user to an output file. The program works fine and is shown below:
import java.io.*;
public class FileStreamsTest {
public static void main(String[] args) {
try {
File inputFile = new File("newbousrs.txt");
File outputFile = new File("outagain.txt");
FileInputStream fis = new FileInputStream(inputFile);
FileOutputStream fos = new FileOutputStream(outputFile);
int c;
while ((c = fis.read()) != -1) {
fos.write(c);
fis.close();
fos.close();
} catch (FileNotFoundException e) {
System.err.println("FileStreamsTest: " + e);
} catch (IOException e) {
System.err.println("FileStreamsTest: " + e);
What I would like to do after each write is to execute a DOS command that looks something like this: supervsr.exe -USER username -PASS password -IMPORTUSERS importfile.txt
The DOS command above will add each user to the system I want to as the loop goes through each user record.
How do I execute the DOS command above inside java?Tried what but still having a problem...here is my code:
import java.io.*;
public class ReadSource {
public static void main(String[] arguments) {
try {
FileReader file = new FileReader("newbousrs.txt");
//FileWriter letters = new FileWriter("outagain.txt");
//PrintWriter pw = new PrintWriter(new FileWriter("outagain.txt"));
BufferedReader buff = new BufferedReader(file);
Runtime rt = Runtime.getRuntime();
boolean eof = false;
while (!eof) {
String line = buff.readLine();
if (line == null)
eof = true;
else
System.out.println(line);
Process proc = rt.exec("\\Blowfish\\droot\\Program Files\\Business Objects\\BusinessObjects 5.0\\supervsr.exe -USER xxxxx -PASS yyyy -IMPORTUSERS \\Blowfish\\droot\\accsp\\public\\newusers\\newbousrs.txt");
//System.out.println(line.substring(4, 10));
//System.out.println(line.substring(3,line.indexOf(',',3)));
buff.close();
} catch (IOException e) {
System.out.println("Error -- " + e.toString());
There error I get is this:
C:\jakarta-tomcat-4.0.3\webapps\webdav\WEB-INF\classes\accsp>java ReadSource
NU,Public,Steve Mcnealy,Steve Mcnealy,U,N,N,Y,N,N,PC,F,Y,N,N
Error -- java.io.IOException: CreateProcess: \Blowfish\droot\Program Files\Busin
ess Objects\BusinessObjects 5.0\supervsr.exe -USER accsp -PASS fish -IMPORTUSERS
\Blowfish\droot\accsp\public\newusers\newbousrs.txt error=3 -
Execute DOS command from java application
Hello,
I want to execute a DOS command (MOVE, in order to move an image from a folder to an other) from a java application. How can I do this?
FrancescoYes I have tested it and it is working but only when executing a bacth file. For instance:
Runtime rt = Runtime.getRuntime();
try{
Process proc = rt.exec("move.bat");
}catch(Exception ex){
ex.printStackTrace();
}and the command in move.bat is:
move c:\\temp\\*.gif C:\\temp2
You don't have to use double slashes in batch files, only in Java. But anyway it is working both ways.
It is not working when you try to execute the command without the batch file:
Process proc = rt.exec("move c:\\temp\\*.gif C:\\temp2"); -> this will not work.
It should work. Try to execute another command to see what happens. -
Execute Process Task :Executing DOS Command lines in Execute Process Task
Hi All,
I am trying to sftp files using Tectia Client from my local system. For that I have used the Execute Process Task in SSIS. First I open DOS command and try to instantiate the sftp3.exe.
Then I write down the below command
binary
open username@hostname
lcd C:\Test
cd <Destination Path name>
put test.txt
How to execute the command in execute process task ?
help is appreciated
ThanksHi ConnectDebz,
According to your description and script example, do you use WinSCP.exe to perform the SFTP files transfer? If so, you should set the Executable of the Execute Process Task to the path of the WinSCP.exe, save the script in a .txt file and set the Argument
of the Execute Process Task like “/script=C:\Temp\sftploader.txt” (without quotes).
References:
http://www.sqlservergeeks.com/blogs/raunak.jhawar/sql-server-bi/395/sql-server-sftp-with-ssis-execute-process-task
http://gregcaporale.wordpress.com/2012/02/23/using-sftp-in-sql-server-ssis/
Regards,
Mike Yin
If you have any feedback on our support, please click
here
Mike Yin
TechNet Community Support -
How to use Runtime execute DOS command?
Hello,
I can not use Runtime class execuste Dos command such as copy and dir.
Is there any suggestion?
Thanks in advance.execute the command with cmd /c (winNT, win2k) or command /c (win9x). Example: "cmd /c dir"
details: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html -
CP5: Problems with Execute Javascript and New/Current window setting
Hello everyone,
I am at my wits' end trying to set this up properly, and I was hoping for some help.
I have inserted a series of buttons designed to open other captivate-created HTM files. I wanted the files to be opened in a controlled window, so I used Execute_Javascript function on the buttons. Here is the code I am using:
void window.open('filename.htm','name','height=680,width=906,left=0,top=0');
I enter that code in the script window. I also want to set it to open in a new window (not reuse the current window), so I used the arrow to the right of the Script_Window button and set it to "New."
When I publish and put it all up on a SharePoint server, it works fine. But then I had to correct a typo on one of my slides (unrelated to this functionality), so I corrected it and republished. The buttons which were working moments before now no longer function. It seems that the "New" setting I had set in the drop-down had reverted to "Current" without me touching it. The Javascript also stopped working. Clicking the button sometimes launches the file in the current window, sometimes in a new window, and sometimes the launch itself fails.
Captivate just seems to forget the New/Current setting all by itself. And for some reason, the actual launching of the file via Javascript also just stops working.
As a test to fix the non-functioning Javascript, I deleted the word "void" then saved the CPTX. Then I added the word "void" back in, saved it again, and published, and now it works. I can't make heads or tails of this, and it is very frustrating, especially since it will delay the delivery of my files.The javascript reads the exact same and yet sometimes it works and sometimes it doesn't.
Has anybody seen this before? How on earth do I fix it?
Thanks!Hi Jim,
Thanks for the feedback. It's good to know that the New/Current issue is a bug and it's not just me.
I tried your suggestion, and I am still having the same problem. I also tried switching to Open File or URL and entering this:
javascript:void window.open('filename.htm','name','height=680,width=906,left=0,top=0' );
Same problem. Sometimes it works and sometimes it doesn't. Code is exactly the same. I can literally put the code in and publish, it works fine, then I can go back into the project, change something completely unrelated (i.e., not touch the javascript), publish again, and now it doesn't work.
Thanks for any additional feedback. -
Execute dos commands in flex. Help !
I have the following dos command to start and stop screen recording from command prompt and it works flawlessly !!
vlc dshow:// :dshow-vdev="None" :input-slave=screen:// :screen-fps=10 --screen-width=640 --screen-height=480 --screen-top=144 --screen-left=192 :sout=#transcode{vcodec=WMV2,vb=1600,scale=1,acodec=wma2,ab=64,channels=1,samplerate=1102 5}:std{access=file,mux=asf,dst=c:/check_cj.wmv} --high-priority && vlc screen:// --one-instance -I dummy --dummy-quiet --extraintf rc --rc-host localhost:8088 --rc-quiet --screen-follow-mouse --no-video :screen-fps=15 :screen-caching=300 --sout=#transcode{vcodec=h264,vb=400,fps=5,scale=1,width=1024,height=768,acodec=none}:dup licate{dst=std{access=file,mux=mp4,dst=C:/capture_final.mp4}}
How can i run this from the air application. Can any one provide me the exact code ??? I tried it via native process but ended up with a error. Please help !have you tried running cmd.exe and adding that command as arguments to the native process running cmd.exe? That is the next thing I would try.
-
Using cfexecute to execute dos command in windows.
Hi!
Well i have a requirement where i need to check status of
particular service in windows from time to time.
I inferred that we can use cfexecute for this. Well i tried
to use the same but i was not successful in achieving the desired
result.
The following is the code i have written for the above
purpose.
<cfexecute name="sc query Internet Information Services"
arguments="y"
outputfile="d:\Temp\Output.txt"
timeout="90" />
I get the following message:
oldfusion.tagext.lang.ExecuteTag$TimeoutException: Timeout
period expired without completion of sc query Internet Information
Services
at
coldfusion.tagext.lang.ExecuteTag.doStartTag(ExecuteTag.java:170)
at
cfserverchecking2ecfm748178803.runPage(D:\Test\serverchecking.cfm:3)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:147)
at
coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:357)
well i have tried using different timeout periods but it dint
work for me.i have gone crazy with it.
Please advice on this.
Many thanks.In addition to Mr Black's suggestions, take a look at these
two entries about using cfexecute on Ben Forta's blog
http://www.forta.com/blog/index.cfm/2006/7/31/Using-CFEXECUTE-To-Execute-Command-Line-Util ities
http://www.forta.com/blog/index.cfm/2006/9/11/A-Couple-Of-CFEXECUTE-Gotchas
Maybe you are looking for
-
Calling a web service from BPEL using java web methods
Hello everyone, I have an application my BPEL process should connect to. The application which is a web service needs to be called using pre defined web methods defined in java from my bpel process using Jdev 10g. Any suggestions in how I can go abou
-
My internet has started running extremely slowly for no apparent reason. Please help?
The internet on my Macbook suddenly started running very slowly, it can take 5-10 minutes to load a page. This isn't a problem with my internet connection as our other devices are working fine. I have tried installing updates but seems to be too slow
-
Problem with notification centre in ios 7
Since installing Ios 7 i have a problem with the Notification Centre which i hope is just a setting i can change. The problem is that i play a number of ongoing games. These games send me notifications of free coins to use to buy clues, or in one o
-
How do i get wifi on my ipod back working?
I installed mywi but it didnt work so i deleted it but now when i try my home internet it doesnt automatically connect and when I try manualy connecting, it says password incorrect for my internet please help!!!
-
Hi, I am occasionally seeing ORA-01555 in the alert log file, but the query length is so long that I could not see the full query in the alert log file. Where can i view the query which is causing this issue? Thanks SA