System cannot find the file specified when I try to call an executable file in C#

StackOverflow https://stackoverflow.com/questions/20530089

  •  31-08-2022
  •  | 
  •  

문제

I'm running a C# script in SSIS. In that script, I'm trying to call winSCP.com which is located in the following directory: "C:\Program Files (86)\WinSCP\"

But when I try to run the code, it always fails immediately.
Here is my code. what am I doing wrong?

// Run hidden WinSCP process

Process winscp = new Process();
winscp.StartInfo.WorkingDirectory = "C:\\Program Files (x86)\\WinSCP\\";
winscp.StartInfo.FileName = "winSCP.com";
winscp.StartInfo.UseShellExecute = false;
winscp.StartInfo.RedirectStandardInput = true;
winscp.StartInfo.RedirectStandardOutput = true;
winscp.StartInfo.CreateNoWindow = true;
winscp.Start();

The Error: "System.ComponentModel.Win32Exception: The system cannot find the file specified at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)"

도움이 되었습니까?

해결책

winscp.StartInfo.FileName = "C:\\Program Files (x86)\\WinSCP\\WinSCP.com";

다른 팁

When you do not use shell execute. You must use the full path to the executed file. Because that in this case the working directory is not base directory to relative path. But just working folder for the executed file.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top