在路径空间调用从研发一个批处理文件时出现的问题 [英] Problems with spaces in paths when calling a batch file from R

查看:164
本文介绍了在路径空间调用从研发一个批处理文件时出现的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些问题调用在Windows中使用从研发叫molconvert一个命令行程序系统()。 molconvert位于C:\\ Program Files文件\\ ChemAxon \\ MarvinBeans \\ BIN
那么我想引用系统()壳()来模拟天生我会通过键入实现

  molconvert PDBC:\\分子转换\\ cembrene A.mol

在命令提示符下,收集得到的输出回至R如

  OUT =系统(...,实习生= T)

我似乎有麻烦,虽然与反斜杠,并在路径的空间。
我试着用

  dirmolconvert =C:\\\\ Program Files文件\\\\ \\\\ ChemAxon \\\\ MarvinBeans斌
外壳(shQuote(膏(dirmolconvert,\\\\ molconvert PDBC:\\\\ cembrene A.mol09月=))​​)

但给了我错误:意外的符号......?和逃避了也于事无补,我应该如何解决这个有什么想法

 系统(膏(dirmolconvert,\\\\ molconvert PDB \\C:\\\\ cembrene A.mol \\09月=),实习生= T)

但给我

 'C:\\ PROGRAM'未找到

有什么想法?

编辑:
基于这样做的正确的方式下面的答案显然是

  inputdir =C:/用户/ Ento /文件/ GCMS / molconvert测试
molconvertdir =C:/ Program Files文件/ ChemAxon / MarvinBeans / BIN
分子=cembrene A.mol
出=系统(糊(shQuote(file.path(molconvertdirmolconvert.bat)),
             PDB
             shQuote(file.path(inputdir,分子))),实习生= T)


解决方案

您想要使用 shQuote 来引用的可执行文件的路径的,而不是整个命令行。根据您的molconvert程序需要什么,你可能还需要引用是参数的路径吧。

 系统(膏(shQuote(file.path(dirmolconvertmolconvert.exe)),
             PDB
             shQuote(C:\\\\分子转换\\\\ cembrene A.mol))

I have some problems to call a command line program called molconvert from R using system() in Windows. molconvert is located in "C:\Program Files\ChemAxon\MarvinBeans\bin" I would then like to invoke system() or shell() to mimick what I would achieve by typing

molconvert pdb "C:\molecule conversions\cembrene A.mol"

at the command prompt and collect the resulting output back to R as in

out=system(...,intern=T)

I seem to have trouble though with the backslashes and the spaces in the paths. I tried with

dirmolconvert="C:\\Program Files\\ChemAxon\\MarvinBeans\\bin"
shell(shQuote(paste(dirmolconvert,"\\molconvert pdb "C:\\cembrene A.mol",sep="")))

but that gives me "Error: unexpected symbol in ..." and escaping the " also doesn't help. Any thoughts on how I should resolve this?

or

system(paste(dirmolconvert,"\\molconvert pdb \"C:\\cembrene A.mol\"",sep=""), intern=T)

but that gives me

'C:\Program' not found

Any thoughts?

Edit: Based on the answer below the right way to do this apparently is

inputdir="C:/Users/Ento/Documents/GCMS/molconvert test"
molconvertdir="C:/Program Files/ChemAxon/MarvinBeans/bin"
molecule="cembrene A.mol"
out=system(paste(shQuote(file.path(molconvertdir, "molconvert.bat")),
             "pdb",
             shQuote(file.path(inputdir,molecule))),intern=T)

解决方案

You want to use shQuote to quote the path to the executable, not the entire command line. Depending on what your molconvert program expects, you may also want to quote paths that are arguments to it.

system(paste(shQuote(file.path(dirmolconvert, "molconvert.exe")),
             "pdb",
             shQuote("C:\\molecule conversions\\cembrene A.mol"))

这篇关于在路径空间调用从研发一个批处理文件时出现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆