Executing .cmd with Runtime.exec()
I'm trying to run a file with the following cod:
Runtime rt = Runtime.getRuntime();
String[] command ={"cmd.exe","/c","start","c:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\c\\rahul_facedetect.cmd"};
try{
Process proc = rt.exec(command);
}
catch(Exception e){System.out.println("error with proc" + e.getMessage());}
With the code, a command prompt is opened, but my .cmd file is not. Does anyone know how to fix this? Please don't send me a link to the "When Runtime.exe() Won't" ; I have already looked through this. Thanks!
So I read some more threads about Runtime.exec() usage, and I found that it is not possible to exec a .cmd file. I replaced my String[] command as follows:
String[] command = {"cmd.exe", "/c", "start", "rahul_facedetect.exe --cascade=C:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\OpenCV\\data\\haarcascades\\haarcascade_frontalface_alt.xml"};
and I get the same error.
Okay, I tried that, and the code compiled fine, but I got this runtime error:
error with procCreateProcess: "C:\Documents and Settings..." error = 123
My code is :
Runtime rt = Runtime.getRuntime();
String[] command = {"C:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\c\\rahul_facedetect.exe --cascade=C:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\OpenCV\\data\\haarcascades\\haarcascade_frontalface_alt.xml"};
try{
Process proc = rt.exec(command);
System.out.println("tried to execute .cmd");
}
catch(Exception e) {System.out.println("error with proc" + e.getMessage());}
}
I am sure that the command C:\Documents and Settings... works; I've tried it separately in a command prompt. Any suggestions? Thanks for the help!
I've never created a batch file, but I made this simple batch file and it does not work. When I run it, it simply opens up a command prompt instead of opening the program. Could you tell me what I'm doing wrong? Thanks!
start "C:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\c\\rahul_facedetect.exe --cascade=C:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\OpenCV\\data\\haarcascades\\haarcascade_frontalface_alt.xml"
yea you quoted the whole thing.
also try to use some style.
put some pride into making a kick @ss lame batch file
@ECHO OFF
REM ********************
REM * Created by: ME
REM * Created on:
REM ********************
TITLE Run My Program!
set %PATH%="C:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\c\\"
set %PARM1%=--cascade="C:\\Documents and Settings\\Rahul Shroff\\Desktop\\svn\\trunk\\OpenCV\\data\\haarcascades\\haarcascade_frontalface_alt.xml"
@ECHO ON
start %PATH%\rahul_facedetect.exe %PARM1%
--
I dont know if my sets are right but spice it up. Keep it fun.