【发布时间】:2019-03-10 00:06:14
【问题描述】:
在windows的ruby中,执行cmd提示命令'move'会报错“命令的语法不正确。”
但它在 ruby 之外工作
C:\rubytest>echo asdf>c:\techprogs\azzz.azz
C:\rubytest>del c:\techprogs\azzz.azz
C:\rubytest>echo asdf>c:\techprogs\azzz.azz
C:\rubytest>move /y c:\techprogs\azzz.azz c:\techprogs\autorun.bat
1 file(s) moved.
C:\rubytest>move /y c:\techprogs\azzz.azz c:\techprogs\autorun.bat
The system cannot find the file specified.
C:\rubytest>
以上所有内容都很好,符合预期。
请注意,我从未收到“命令的语法不正确”的错误消息。
然后在 ruby 中尝试
我有一个简单的文件,只有一行
C:\rubytest>type syntaxcommandincorrect.rb
`move /y c:\techprogs\azzz.azz c:\techprogs\autorun.bat`
C:\rubytest>
但它给出了关于语法的错误
C:\rubytest>del c:\techprogs\azzz.azz
C:\rubytest>ruby syntaxcommandincorrect.rb
The syntax of the command is incorrect.
C:\rubytest>echo asdf>c:\techprogs\azzz.azz
C:\rubytest>ruby syntaxcommandincorrect.rb
The syntax of the command is incorrect.
C:\rubytest>
【问题讨论】:
-
记住反引号内的反斜杠有特殊含义,需要转义。考虑:
move /y c:\\techprogs ... -
@tadman 谢谢,大概就是这样,等我回到那台电脑上去看看