views:

41

answers:

3

Hello!
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.
What I am doing wrong? Thanks in advance

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??

A: 

you missed the second %. Should be:

echo %filename% | sed 's/\([A-Z]\)/ \1/g';

dogbane
I tried it. the same result, but now it prints %filename%
mujer esponja
are you running the bat file at a windows cmd prompt?
dogbane
A: 

%filename is missing a % at the end. It should be: %filename%

Ruel
+1  A: 

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).

Grodriguez
I get this error in my eclipse console: Cannot run program "cmd /c myscript.bat" (in directory "mydirectory"): error=2, No such file or directory. But of course, myscript.bat is in that directory
mujer esponja
try splitting up the command in several strings: `("cmd.exe", "/c", "script.bat")`
Grodriguez
thanks! was it.
mujer esponja