当两个路径都有空格时,如何使用 C 程序中的文件启动外部程序?
我正在尝试使用 VS2005 修复现有的 C 程序,该程序最终
int system(command) //in C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\system.c)
使用参数值调用
start C:\Program Files\VideoLAN\VLC\vlc.exe C:\Documents and Settings\me\My Documents\My Music\09 - Track09.mp3
要启动的程序,文件名路径均由获得的环境变量组成,并且命令 start 附加到 char 缓冲区的开头。环境变量为:
%VLCPATH%
,其值为C:\Program Files\VideoLAN\VLC
%MUSIC%
其值为C:\Documents and Settings\me\My Documents \My Music
我一直在尝试这与 XP 命令提示符一起使用,当路径没有空格时一切正常。这也有效:
"%VLCPATH%\vlc.exe" "%MUSIC%\09 - Track09.mp3"
那我该怎么办?
- 编辑环境变量以包含引号吗? (不这么认为)
- 检查命令是否有文件作为参数,然后以某种方式添加带有转义字符的引号,也许它们两个并删除单词开始?
- 做一些我不知道的明智/优雅的事情
I'm trying to fix an existing C-program with VS2005 that eventually calls
int system(command) //in C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\system.c)
with parameter value
start C:\Program Files\VideoLAN\VLC\vlc.exe C:\Documents and Settings\me\My Documents\My Music\09 - Track09.mp3
the program to be started and the filename paths are both formed from env variables that are got and the command start is appended to start of char buffer. The env variables are:
%VLCPATH%
which has valueC:\Program Files\VideoLAN\VLC
%MUSIC%
which has valueC:\Documents and Settings\me\My Documents\My Music
I've been trying this with XP Command Prompt and everything works fine when paths don't have spaces. Also this works:
"%VLCPATH%\vlc.exe" "%MUSIC%\09 - Track09.mp3"
So what should I do?
- edit env variables to have quotes? (Don't think so)
- check if command has file as parameter and then somehow add quotes with escape character to maybe both of them and remove the word start?
- do something sensible / elegant that I'm not aware of
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会尝试引用所有参数,例如:
显然将可执行文件和参数替换为您确定的可执行文件和参数。
I would try quoting all of the parameters, for example:
Obviously replace executable and param with however you determine your executable and params.
在 Windows 中,如果程序启动路径和任何带有路径名的参数包含空格,则都需要用双引号括起来(“像这样”)。
例如:
“C:\Program Files\VideoLAN\VLC\vlc.exe”“C:\Documents and Settings\me\My Documents\My Music\09 - Track09.mp3”
In Windows, both the program path to start and any arguments with pathnames need to be enclosed in double quotation marks ("like this") if they contain spaces.
For example:
"C:\Program Files\VideoLAN\VLC\vlc.exe" "C:\Documents and Settings\me\My Documents\My Music\09 - Track09.mp3"