문제

I am attempting to transition from VB script to C# with some legacy code that a colleague has. I cannot seem to determine how to transfer this line over. Any assistance would be helpful.

Set objShell = CreateObject("wscript.shell")
objShell.Run """C:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt.com"" -f P:\share\getfiles.scp", 1, True
Set objShell = Nothing
도움이 되었습니까?

해결책

This is from some old note I dug up, but should work:

Process proc = new Process();

proc.StartInfo.FileName = @"C:\Program Files\Ipswitch\WS_FTP Professional\ftpscrpt.com";
proc.StartInfo.Arguments = @"-f P:\share\getfiles.scp";
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
// start the process
proc.Start();
// wait for it to finish
proc.WaitForExit(5000);     
// get results
string output = proc.StandardOutput.ReadToEnd();
string error = proc.StandardError.ReadToEnd();

다른 팁

I suppose the exact C# equivalent would be this:

var objShell = Microsoft.VisualBasic.Interaction.CreateObject("wscript.shell");
objShell.Run("\"C:\\Program Files\\Ipswitch\\WS_FTP Professional\\ftpscrpt.com\\" -f P:\share\getfiles.scp", 1, true);
objShell = null;

But really, you should just add a reference to the assembly in question and call its methods directly.

See the example (Scroll down to examples) for information on executing the command. You can try to change the UseShellExecute option to get a close result.

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