shquote()breaks system()命令而不是逃脱空间
我正在运行R脚本中的GCMS软件AMDI,以分析GCMS数据。基本语法是:
system("AMDIS_PATH GCMS_FILE_PATH /S /GC /GE /E"
使用“ /s /gc /ge /e”,指AMDIS程序中的功能。
我想制作代码为“万无一失”,因此我允许使用“/”而不是“ \\”的路径。而且我还允许路径中的空间,用shquote(...,type =“ cmd”)
逃脱它们,
这意味着完整的代码看起来
system(paste(shQuote(gsub("/", "\\", AMDIS_PATH, fixed = T), type = 'cmd'), shQuote(gsub("/", "\\", GCMS_FILE_PATH, fixed = T), type = 'cmd'), "/S /GD /GS /E"))
此代码不起作用(output = 65535) ,但是有一个问题:
如果我从gcms_file_path中删除shquotes。然后,一切都应该像它一样工作(只要File_path不包含任何空间)。 因此,执行这样的代码确实有效:
system(paste(shQuote(gsub("/", "\\", AMDIS_PATH, fixed = T), type = 'cmd'), gsub("/", "\\", GCMS_FILE_PATH, fixed = T), "/S /GD /GS /E"))
任何想法Shquote为AMDIS_PATH的工作正常,而对于GCMS_FILE_PATH不适合?以及如何运行代码并仍然在GCMS_FILE_PATH中逃脱空格?
I'm running the GCMS software AMDIS inside an R script to analyze GCMS data. The basic syntax is:
system("AMDIS_PATH GCMS_FILE_PATH /S /GC /GE /E"
With "/S /GC /GE /E" referring to functionalities within the AMDIS program.
I want to make the code 'fool-proof', so I'm allowing paths with "/" instead of "\\". And I'm also allowing spaces in the paths, escaping them with shQuote(..., type = "cmd")
Which means the full code looks like
system(paste(shQuote(gsub("/", "\\", AMDIS_PATH, fixed = T), type = 'cmd'), shQuote(gsub("/", "\\", GCMS_FILE_PATH, fixed = T), type = 'cmd'), "/S /GD /GS /E"))
This code does not work (output = 65535), but there's a catch:
If I remove the shQuotes from my GCMS_FILE_PATH. Then everything works like it should (so long as the FILE_PATH does not contain any spaces).
So executing the code like this does work:
system(paste(shQuote(gsub("/", "\\", AMDIS_PATH, fixed = T), type = 'cmd'), gsub("/", "\\", GCMS_FILE_PATH, fixed = T), "/S /GD /GS /E"))
Any idea why shQuote works fine for the AMDIS_PATH, but not for the GCMS_FILE_PATH? And how I can run my code and still escape spaces in the GCMS_FILE_PATH?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有一个可重复的示例很难说发生了什么在这里,请注意,
?系统
说:因此,使用
type ='cmd'
可能完全不合适,请考虑使用system2
而不是。您的问题可能与您期望的
System
要做的事情或期望shquote
要做的事情。您可以通过System
用CAT
来轻松地解开两者,以调试。Without a reproducible example it's hard to say what is going on here, but note that
?system
says:So escaping with
type = 'cmd'
might not be appropriate at all, consider usingsystem2
instead.Your issue might either be with what you expect
system
to do or what you expectshQuote
to do. You can easily disentangle the the two by replacingsystem
withcat
for debugging.