Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F# FSI和F中的外部程序启动和输出重定向#_F# - Fatal编程技术网

F# FSI和F中的外部程序启动和输出重定向#

F# FSI和F中的外部程序启动和输出重定向#,f#,F#,我有以下代码: let p = new System.Diagnostics.Process(); printfn "installing %A" "installing" p.StartInfo.FileName <- "powershell.exe"; p.StartInfo.Arguments <- ("/c notepad.exe") p.StartInfo.RedirectStandardOutput <- true p.StartInfo.UseShellExecu

我有以下代码:

let p = new System.Diagnostics.Process();
printfn "installing %A" "installing"
p.StartInfo.FileName <- "powershell.exe";
p.StartInfo.Arguments <- ("/c notepad.exe")
p.StartInfo.RedirectStandardOutput <- true
p.StartInfo.UseShellExecute <- false
p.Start() 
printfn "result ?"
printfn "result %A" (p.StandardOutput.ReadToEnd())
printfn "done"
let p=new System.Diagnostics.Process();
printfn“安装%A”“安装”

p、 StartInfo.FileName我在VS中的F#Interactive(突出显示代码并点击Alt+Enter)中,或者在shell中使用“fsi Script.fsx”(Visual Studio 2013/.NET 4.5.1)运行它时,都没有看到这种行为

我确实必须在交换机中添加“-executionpolicy remotesigned”以避免出现异常(即使在正常的PS shell中,这已经设置好了),但如果您没有PowerShell配置文件,则可能不会出现这种情况

我看到的是:

(Notepad opens)
installing "installing"
result ?
(I close notepad)
result ""
done
我正在使用
fsi Script.fsx
运行以下代码。我在PowerShell窗口和普通CMD提示符中都尝试了它

let p = new System.Diagnostics.Process();
printfn "installing %A" "installing"
p.StartInfo.FileName <- "powershell.exe";
p.StartInfo.Arguments <- ("-executionpolicy remotesigned /c notepad.exe")
p.StartInfo.RedirectStandardOutput <- true
p.StartInfo.UseShellExecute <- false
p.Start() 
printfn "result ?"
printfn "result %A" (p.StandardOutput.ReadToEnd())
printfn "done"
let p=new System.Diagnostics.Process();
printfn“安装%A”“安装”

p、 StartInfo.FileName它打印“完成”而你不碰任何东西?是的…并打开记事本。VS2010.NET4.0真奇怪。在这里,它在记事本之前打印消息,启动记事本,我关闭。。。在我按下回车键之前什么都没有,那么我已经“完成”了啊,没有,对不起。我以为在你点击完成之前它不会打开记事本。我看到了同样的行为。您对记事本中的标准输出有何期望?在打印“完成”之前,您可能需要
p.WaitForExit()
。这是MSDN中的一个示例。