- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
让我想编写一个应用程序来启动另一个应用程序。像这样:
# This will launch another_app.exe
my_app.exe another_app.exe
# This will launch another_app.exe with arg1, arg and arg3 arguments
my_app.exe another_app.exe arg1 arg2 arg3
这里的问题是我在 main
函数中获取了 char* argv[]
,但我需要将其合并到 LPTSTR
以便将其传递给 CreateProcess
。
有一个 GetCommandLine
函数,但我无法使用它,因为我正在从 Linux 移植代码并绑定(bind)到 argc/argv
(否则,这是一个非常难看的 hack对我来说)。
我无法轻松地手动合并参数,因为 argv[i]
可能包含空格。
基本上,我想要的是 CommandLineToArgvW
的相反内容。有没有标准方法来做到这一点?
最佳答案
有关如何引用论点的明确答案位于 Daniel Colascione 的博客上:
我不愿意在这里引用代码,因为我不知道许可证。基本思想是:
for each single argument:
if it does not contain \t\n\v\",
just use as is
else
output "
for each character
backslashes = 0
if character is backslash
count how many successive backslashes there are
fi
if eow
output the backslashs doubled
break
else if char is "
output the backslashs doubled
output \"
else
output the backslashes (*not* doubled)
output character
fi
rof
output "
fi // needs quoting
rof // each argument
如果您需要将命令行传递给cmd.exe,请参阅文章(有所不同)。
我认为 Microsoft C 运行时库没有执行此操作的函数,这太疯狂了。
关于c++ - 如何将 argv 转换为 CreateProcess 的 lpCommandLine 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31838469/
我在 CreateProcess 函数中为参数 lpCommandLine 分配内存,使用 malloc 或在堆栈上。 我能否在调用后立即释放/释放该内存,还是必须等到进程完成? 最佳答案 lpCom
arg我有一些代码: CreateProcess(L"D:\\prog\\forLb1SPZ.exe",L"D:\\prog\\forLb1SPZ.exe D:\\1.txt",NULL,NULL,F
我一直在使用 CreateProcess Win API,我想知道使用 lpApplicationName 和 lpCommandLine 作为参数与使用 lpCommandLine 之间的区别是什么
让我想编写一个应用程序来启动另一个应用程序。像这样: # This will launch another_app.exe my_app.exe another_app.exe # This will
我似乎无法找到明确的答案。我的目标是使用用户 token 启动一个进程。比如说,有问题的过程是这样开始的: "C:\My folder\My proc.exe" param=1 因此,当我为 Crea
我是一名优秀的程序员,十分优秀!