分割可执行文件路径和参数可执行文件、路径、参数

由网友(ミ﹏蕞蒗漫の副歌)分享简介:我需要能够分裂的命令的可执行文件路径和参数。 I need to be able to to split the executable path and arguments in a command. Windows处理易如下:Windows handles the following easily:的notep...

我需要能够分裂的命令的可执行文件路径和参数。

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:testfolderversioninfo.txt"

C: WINDOWS NOTEPAD.EXEC: test文件夹 versioninfo.txt

"C:Windowsnotepad.exe" "C:test folderversioninfo.txt"

RUNDLLC:的Windows somelibrary.dll

rundll "CWindowssomelibrary.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
阅读全文

相关推荐

最新文章