I have two batch files to execute SFTP commands.
- Inner batch file
- Outer batch file
Inner batch file contains below code :
put D:\Source_Data\SFTP\Sample.xml
Outer batch file contains below code:
psftp -b D:\Source_Data\SFTP\Innerbatch.bat -l username -i D:\WebCash\privatekey.ppk @server.domain.com
Outer batch file internally calls inner batch file. How to execute the batch files using C# code?
Also I need to get the error code (i.e) whether the batch file is executed successfully or not in C# code.
I used the below code to execute the batch files.
Process p = null;
p = Process.Start(@"C:\Batch\file.bat");
p.WaitForExit(1000);
p.ExitCode;
but getting error. Required info does not be determined while process is executing.
Problem is Windows Service. I can able to run the batch file through normal Windows form application. But when I used the same code in Windows Service the process is not exiting.
System.Diagnostics.Processclass.Process.Start(@"Batchfilepath");beProcess.Start(Batchfilepath);?