1
以下程序崩溃。我究竟做错了什么?简单的代码在C崩溃中产生一个进程。为什么?
#include <stdio.h>
#include <process.h>
int main() {
puts("Hello!");
return spawnlp(0, "notepad.exe", "notepad.exe", "test.txt");
}
以下程序崩溃。我究竟做错了什么?简单的代码在C崩溃中产生一个进程。为什么?
#include <stdio.h>
#include <process.h>
int main() {
puts("Hello!");
return spawnlp(0, "notepad.exe", "notepad.exe", "test.txt");
}
您错过了作为参数列表的一部分传递的终止NULL。
如果没有终止,参数列表将不会被称为年底,系统将继续阅读这会导致undefined behavior由于无效的内存位置访问。
同[你昨天的问题(http://stackoverflow.com/questions/43187986/how-do-i-know-when-i-ought-to-free-strings-in-c-returned- by-library-functions):这个人拥有你所需要的一切:_Argv的最后一个成员必须是一个NULL指针._L – LPs
@LPs:它具有它。我读过它,但我没有正确处理它:当我读到它时,我认为这个要求适用于'spawnvp()'(它接受一个数组)而不是'spawnlp()'(它带有一个参数列表)。这是否使我变成傻瓜或是“人”无效的援助?我想我已经知道你的意见了。 – 7vujy0f0hy