分割可执行文件路径和参数 [英] Split executable path and arguments
本文介绍了分割可执行文件路径和参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够分裂的命令的可执行文件路径和参数。
I need to be able to to split the executable path and arguments in a command.
Windows处理易如下:
Windows handles the following easily:
的notepad.exe C:\ TESTFILE.TXT
"notepad.exe C:\testfile.txt"
记事本C:\ testfolder \ versioninfo.txt
"notepad c:\testfolder\versioninfo.txt"
C:\ WINDOWS \ NOTEPAD.EXEC:\ test文件夹\ versioninfo.txt
"C:\Windows\notepad.exe" "C:\test folder\versioninfo.txt"
RUNDLLC:\的Windows \ somelibrary.dll
rundll "C\Windows\somelibrary.dll"
任何人有一张code解析这些字符串?
Anyone has a piece of code to parse such strings?
感谢。
推荐答案
我用这样的事情在过去的:
I've used something like this in the past:
char* lpCmdLine = ...;
char* lpArgs = lpCmdLine;
// skip leading spaces
while(isspace(*lpArgs))
lpArgs++;
if(*lpArgs == '\"')
{
// executable is quoted; skip to first space after matching quote
lpArgs++;
int quotes = 1;
while(*lpArgs)
{
if(isspace(*lpArgs) && !quotes)
break;
if(*lpArgs == '\"')
quotes = !quotes;
}
}
else
{
// executable is not quoted; skip to first space
while(*lpArgs && !isspace(*lpArgs))
lpArgs++;
}
// TODO: skip any spaces before the first arg
这篇关于分割可执行文件路径和参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文