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
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 want to open an EXE file from a Java program. I tried 2 procedures.
The program can run some programs, like NotePad++, but cannot run my C++ EXE file. I tried:
Process exec = Runtime.getRuntime().exec(file.getAbsolutePath());
ProcessBuilder processBuilder = new ProcessBuilder(file.getAbsolutePath());
but neither of the above work. No exception is thrown, and exec.isAlive = true.
Your mistake is that you took the absolute path in the first procedure.
Try using a relative path, I just tested and it worked just fine.
This also works for me (using 2 backslashs').
Runtime.getRuntime().exec("C:\\Program Files\\DDNet\\DDNet.exe");
Kind regards
I've created Java runtime image for a simple OpenJFX application. In order to run this app, jlink auto-generated two lauch scripts under %image_path%/bin directory. This how it looks like (the one for Windows):
#echo off
set JLINK_VM_OPTIONS=
set DIR=%~dp0
"%DIR%\java" %JLINK_VM_OPTIONS% -m app/com.package.Launcher %*
Obviously, when I run this batch file it opens new shell window, which is not what I want to. I've tried all common approaches: use javaw instead of java, run script via start command etc. Nothing works.
Is it possible to avoid shell window or somehow create native launcher?
Ok, I've figured out it's not posiible to eliminite shell window completely. In the best scenario it's just flickers for ~1sec. This is how it can be achieved:
#echo off
set JLINK_VM_OPTIONS=
set DIR=%~dp0
start "" "%DIR%\javaw" %JLINK_VM_OPTIONS% -m app/com.package.Launcher %* && exit 0
There is a feature request about native laucher implementation but it's not discussed actively.
Nonetheless I've solved the problem. There is "Batch to EXE Converter" tool. It can generate executable (basically the same batch file) which can run your app silently.
This looks to be possible using vbscript. If you put the following script into a .vbs file next to the launcher.bat file (or whatever the name of the batch file is):
CreateObject("Wscript.Shell").Run CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\launcher.bat " & WScript.Arguments(0) & " > " & CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\launch-log.log", 0, False
This runs the batch file in the same directory, and also redirects stdout to a log file.
What you´d like to achieve is very well possible. It is actually even quite easy and I use this every day. There already is an early access build of jpackage available here: http://jdk.java.net/jpackage/ Creating executables works already
nicely (I use it on Mac and Windows). Only creating installers is still a bit problematic.
It's very easy to run a bat file without showing the cmd window.
you just need to create VBS file to run bat file with the following cmd
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & ".\bin\launcher.bat" & Chr(34), 0
Set WshShell = Nothing
Save cmd in the file out of the bin folder with any name like
Launcher.vbs.
I have put the necessary files on my USB pen drive, the Java Development Kit and the Eclipse files. I have created a .bat file which reads
#echo off
set Path=\32 Bit\jdk32\bin;%Path%
cd "32 Bit\Eclipse"
start eclipse.exe
exit
However when I run the batch, Eclipse launches and brings the error
As far as I can tell this is trying to use my old path variable for the JNI Shared Library. Could someone help me with this problem please.
It turns out there is a really simple solution to this.
Amended .bat file
#echo off
set Path=%~dp032 Bit\jdk32\bin;%Path%
cd "32 Bit\Eclipse"
start eclipse.exe
exit
Explanation
This works by getting the path of an executing batch file using the command %~dp0.
Where
d is the drive (in this case N:\)
p is the path (Code\Java\Eclipse Mars\)
0 is the name of the executing batch file
This path N:\Code\Java\Eclipse Mars\32 Bit\jdk32\bin which sets the Java version correctly and removes the error I had above
you don't need the batch script you can just change the -vm config directive and it will build the virtual machine from the exe for java you give it.
ex. -vm C:\jdk1.7.0_21\bin\javaw.exe. https://wiki.eclipse.org/Eclipse.ini#-vm_value:_Linux_Example
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..!! :)