I just tried to execute a java command using runtime like this:
Runtime.getRuntime().exec("shutdown -s");
to shutdown the computer, but I am training on a project that will get both my electronics and computer skills so I want to execute an avrdude command to program the mcu from Java and make a GUI program. So I want the cmd window to be visible when I run the command. I just made it visible by:
Runtime.getRuntime().exec("cmd.exe /c start");
but I cant write on the window I just created, any help pls????
thanks all
Following would do it for you.
CMD.EXE /K your_command
I got an idea but still need some help!
What about making a .bat file and running it using java File class
but still when I make a bat file and try to run I get the command multiple times like this:
http://i.imgur.com/cMddMh5.png
but all I did was only write avrdude in the bat file:
http://i.imgur.com/PDbi2vJ.png
still need help in that!!
thanks for all answers...
EDIT::
I just looked it up in the internet and figured out a solution which is making a .cmd file instead of a .bat file and that worked great without looping thanks for all the repliers..!! :)
Related
I am running a java program using a .bat file. It works well after double clicking direcctly on the .bat, that's not the problem.
What I want now, is to run that .bt file (and the java program by extends) from the cmd at first, and then to be able to compile it from any other machine.
I have followed at first the following answer : How do I run a java program from a different directory? , but it didn't work for me.
Here is my .bat file :
#echo on
set CLASSPATH=%CLASSPATH%;.;lib/console.jar;lib/log4j-1.2.13.jar;lib/prog1.jar;lib/prog1_newOption.jar;lib/org.hamcrest.core_1.3.0.v201303031735.jar;lib/RXTXcomm.jar;lib/trace.jar;lib/xercesImpl.jar;lib/xml-apis.jar
java -cp "$/prog1_newOption/src/main/Main" %UsersCommand%
pause
exit
%cmd%
Maybe have I to look for the main path in the .bat file and then parse it the the "java command programm" line?
Thank you so much for your help
I need to start a Java application in the console by "double-clicking" the jar file. I found a workaround to achieve that:
Process p = Runtime.getRuntime()
.exec("cmd /c start cmd.exe /k \"java -jar CourseProjectServer.jar\"");
It runs pretty well, sure. But as you may guess it... Creates an infinite amount of itself until I stop it cause this is basically the first line of the application so when it starts it creates a new instance.
I came up with an idea like to start the process then grab it`s PID, save it in a file for example and then checking whether it is still running but found no way to do so.
Any suggestions? Is there a proper and not idiomatic way to achieve this?
P.S.: I know I can create a bat file to start the application but I don't want to do that. If that is what you want to write - skip it.
Any help appreciated.
I have this C# program i made and while i can run it fine by clicking the exe file or by clicking on a batch file, I cant start up the program on a java program I made to run it. I have tried this line of code and couldn't get the software to run.
Runtime.getRuntime().exec("nameOfTheExeFile");
or set it to the batch file i made that starts the program.
Runtime.getRuntime().exec("nameOfTheBatchFile");
Now the interesting thing is when I try it with the batch file i get an error saying that the file cannot be found but when i double click the batch file it will start the exe file just fine.
I have even tried to use Process but I am not getting any luck with that process as well
List cmdAndArgs = Arrays.asList(new String[]{"cmd.exe", "/c", "ProgramName.exe"});
ProcessBuilder pb = new ProcessBuilder(cmdAndArgs);
Process p = pb.start();
Strange thing is i dont get any error at all. Even when i try unit testing i don't any error's at all. Is there a process I am missing or something ? I am lost on what to do.
Update:
When i check on the task manager i can see that the program is running but not the exe version. I see ProgramName.vshost.exe , is there a reason for this to be showing and not the exe file ?
Since your program is command line program you need to start it from cmd. I'm not sure if this is the best way to do it, but it works.
Runtime.getRuntime().exec("cmd /c start nameOfTheBatchFile");
Batch file:
start cmd.exe /k "nameOfExeFile"
exit
I have a Java application and i would like to spawn a new process(start a .bat file), that will essintially do the same thing as by double-clicking on it.
I have tried both Runtime.getRuntime().exec() and ProcessBuilder in order to spawn that process. Both those approaches work (they can start the .bat file), but my problem is that they do not actually do the exact same thing as by double clicking on it.
More specifically, this .bat file starts up a JVM (java.exe MyMainClass) which is configured to run using Windows SxS (side by side). Thus, i have created appropriate java.exe.config and java.exe.manifest files. When i doulbe click on that, the java application starts and the appropriate .dlls are loaded succesfuly (reason i need SxS).
My problem is that when i start the exact same .bat file (with the exact same arguments and process environment), either by using ProcessBuilder or Runtime.getRuntime().exec(), it doesn't seem to take into consideration my SxS configuration, thus the .dlls that i need are not loaded at all, resulting in errors.
Does anyone have any clue how to launch this .bat file the same way as windows laucnhes it when i am double clicking on it?
Additionally, does anyone have any experience with Java SxS deployment? I cannot really understand why ProcessBuilder ignores my SxS configuration.
Thanks in advance.
You can try starting a cmd window, which loads your application bat file:
Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"C:\\path\\to\\the\\app.bat arg1 arg2\"");
I need to run a bat file using a java code. I did that in the following way
Process process =Runtime.getRuntime().exec("cmd /c start D:\\Work\\BOSync\\TestFoxPro\\ATSFill.bat");
int exitVal = process.waitFor();
Problem is I can run the bat but the task of the bat not happened. I run the bat to load data from CSV file to oracle database using sqlldr. When I double click on the bat it works fine.
I think the problem is JVM doesn't has enough permission to run the bat. Is there a way to elevate the permission in java?
This sounds like a path issue to me. Try using absolute paths to the binary that you are using in your bat file and set other environment variables that your script need.
As for the cmd window popping up - try just calling the bat file directly and not use the cmd /c command.
Hey guys finally i Sort it out. The problem was in my bat file. It was like that previously. cd \C:\oracle\ora92\bin sqlldr GAMINI/gamini C:\AOTITS\CLSTMAS.ctl log=C:\AOTITS\CLSTMAS.log. Then I remove the path of oracle bin and add it to system path. Then it works fine. Thanks for your help