2

我正在尝试使用同事拥有的一些遗留代码从 VB 脚本过渡到 C#。我似乎无法确定如何转移这条线。任何帮助都会有所帮助。

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
4

3 回答 3

2

这是来自我挖出的一些旧笔记,但应该可以:

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();
于 2013-05-22T15:09:59.097 回答
1

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.

于 2013-05-22T14:57:59.207 回答
1

有关执行命令的信息,请参阅示例(向下滚动到示例)。您可以尝试更改UseShellExecute选项以获得关闭结果。

于 2013-05-22T14:59:59.027 回答