Ruby单行脚本执行返回错误(在Windows上)

时间:2019-06-06 15:21:57

标签: ruby windows

编辑:我发现一个相同的问题已得到回答:How can I escape the vertical bar when doing command line with Ruby

我有my.rb个文件,仅包含一行:

File.popen("myprocess.exe","w"){|file| file.puts "help"; file.puts "quit";}

我可以通过ruby my.rb执行该命令,它就像一个超级按钮。但是,如果我尝试运行以下命令:

ruby -e 'File.popen("myprocess.exe","w"){|file| file.puts "help"; file.puts "quit";}'

它抱怨说“文件”未被识别为内部或外部命令,可操作程序或批处理文件。为了进一步简化,以下行仍返回错误:

ruby -e 'File.popen("myprocess.exe","w"){|file|}'

此代码可以正常工作:

ruby -e 'File.popen("myprocess.exe","w"){}'

我在做什么错? :(

0 个答案:

没有答案
相关问题