I'm trying to run a .bat file in java, but I'm using the specific path(C:..). I was hoping to make it run a bat file inside my src folder in java. How should I code it? this is my current code:
run.exec("cmd start /c C:\Users\mico\workspace\ANTLR java\src\jython2.5.2");
and I also want to put the source file(the path to where the file is saved)
this is the cmd command I'm using:
C:\Users\mico\workspace\ANTLR java\src\jython2.5.2\jython C:\Users\mico\workspace\ANTLR java\src\save.py
How do I execute the entire command while not making it a static path and be able to load the file?
First thing is that you need to have the PWD of your program be set to a known location (the path above the src for example). When you start your jython/ANTLR, you can use ~dp0
and the /D
switch on start
to do that. The second part is that once you know the PWD, you can just use a relative path within your java source.
You can define the file's path in Autoexec.bat file by appending path line or follow this steps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.