如何解决Process.start 用于启动浏览器,但现在已弃用
如果我阅读土星的“如何开始”指南:
https://saturnframework.org/tutorials/how-to-start.html
当我运行最后一步时:
class CLI
def self.start
s=Scraper.new
puts "Welcome to your basic music theory coordinator!"
puts ""
puts "If you want to check out a key,choose from the list below by typing the key as you see it listed."
puts "*not yet functional* If you want to generate a random chord progression in a certain key,just pick the key from the list and say generate"
puts ""
puts "Pick a key:"
puts " "
puts "Major:"
puts s.all_scale_names[0]
puts " "
puts "Minor:"
puts s.all_scale_names[1]
s.key_information_creator
end
end
CLI.start
网络服务器似乎确实启动了。我可以访问 http://localhost:8085/books 并查看生成的应用程序。
但是,如果我在控制台按 ctrl-c 来停止网络服务器,我会注意到以下内容:
如果我查看 9: from lib/comman_line_interface.rb:1:in `<main>'
8: from lib/comman_line_interface.rb:1:in `require_relative'
7: from /home/code/cli-test/test-cli/lib/scraper.rb:4:in `<top (required)>'
6: from /home/code/cli-test/test-cli/lib/scraper.rb:4:in `require_relative'
5: from /home/code/cli-test/test-cli/lib/song.rb:5:in `<top (required)>'
4: from /home/code/cli-test/test-cli/lib/song.rb:5:in `require_relative'
3: from /home/code/cli-test/test-cli/lib/key.rb:6:in `<top (required)>'
2: from /home/code/cli-test/test-cli/lib/key.rb:6:in `require_relative'
1: from /home/code/cli-test/test-cli/lib/comman_line_interface.rb:31:in `<top (required)>'
/home/code/cli-test/test-cli/lib/comman_line_interface.rb:12:in `start': uninitialized constant CLI::Scraper (NameError)
,它包含以下行:
dotnet fake build -t run
在 build.fsx
目标内:
Process.start (fun i -> { i with FileName = "http://localhost:8085" }) |> ignore
所以看起来 Run
目标的意图是为我们启动浏览器。
上面输出中的警告表明:
Target.create "Run" (fun _ ->
let server = async {
DotNet.exec (fun p -> { p with WorkingDirectory = appPath } ) "watch" "run" |> ignore
}
let browser = async {
Thread.Sleep 5000
Process.start (fun i -> { i with FileName = "http://localhost:8085" }) |> ignore
}
[ server; browser]
|> Async.Parallel
|> Async.RunSynchronously
|> ignore
)
Fake 文档中的 Just start a process 页面有一些示例。除了这些,我使用更改后的 Run
来使用以下行:
Warning FS0044: This construct is deprecated. use the CreateProcess APIs instead.
这似乎确实有效。
几个问题:
注意
如果您决定阅读 Saturn“如何开始”指南,我建议您在第 3 步之后删除文件 build.fsx
。默认文件当前查找特定版本的 .NET SDK。有一个 pull-request 可以解决这个问题。
谢谢!
解决方法
您可以查看 Plotly.NET 源代码以了解启动浏览器的方法:https://github.com/plotly/Plotly.NET/blob/62f297649320783ea0e64725ff4703bb225268d0/src/Plotly.NET/ChartExtensions.fs#L16
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。