I am having batch file : sample.bat with following code:
@ECHO OFF
SET /a INT1=%1
SET /a INT2=%2
SET /a ANSWER=INT1*INT2
ECHO %ANSWER%
PAUSE
Also created another batch file : cmdSample.bat
with following code:
sample 2 4
So if i run cmdSample.bat file, it gives me correct result.
After that i have created 1 windows service application in which i tried to call that batch file and pass the command, as follows:
private void DoWork()
{
try
{
string fname = @"C:\Users\of4\Desktop\sample.bat";
string cmd = "sample 2 4";
RunSampleBatch(fname, cmd);
}
}
private void RunSampleBatch(string fname, string cmd)
{
Process p = new Process();
p.StartInfo.FileName = fname;
p.StartInfo.Arguments = cmd;
p.Start();
}
Can anyone help me, why i am not able to execute batch file through windows service application??
Thanks in advance..