How to get parameter in a .bat file from a java project
Yesterday I asked this post, but I am still having problems when I try to 开发者_运维百科run this .bat file from my java project.
@echo off
set filename=%1
echo %filename | sed 's/\([A-Z]\)/ \1/g';
The call I do is:
String param = "myparam";
ProcessBuilder pb = new ProcessBuilder("myFile.bat", param);
But what myFile.bat does is just print %filename
, so it doesn't take the real value of the param I send.
I tried also
@echo off
set filename=%1
echo %filename% | sed 's/\([A-Z]\)/ \1/g';
With the same result, now it prints %filename%
.
Maybe some problems in the call??
You probably want to execute cmd.exe /c script.bat
instead, so that cmd.exe (the command shell) will expand variables. In Windows, .bat files are not full fledged executables, just input files for the command processor (cmd.exe
).
you missed the second %
. Should be:
echo %filename% | sed 's/\([A-Z]\)/ \1/g';
%filename
is missing a %
at the end. It should be: %filename%
精彩评论