Why does windows spawn process sometimes trigger error STATUS_SXS_ASSEMBLY_NOT_FOUND?

非 Y 不嫁゛ 提交于 2019-12-01 14:45:34

This is wrong:

const char *args[1];
args[0] = NULL;

you need

const char *args[2];
args[0] = "notepad";
args[1] = NULL;

Other than that, your example code works, at least when compiled with Visual Studio 2010. I've tested it on both Windows 7 and Windows XP, and it works. Notepad runs.

What compiler are you using?

You are right, the second parameter to _spawnev() takes the name of the app to be executed inlcuding its full path.

To get around to know the path you could call the command processer cmd.exe and pass it along the name of the app to execute as a parameter to it using cmd.exe's option /C.

This works in all the cases where you could have started the application out of one of cmd.exe's command line windows.

cmd.exe knows the value of the environment variable PATH and used it to search through it for the app's path to start.

The path to cmd.exe itself could be read from the environment variable COMSPEC.

Update: For more on this issue (including examples) please read here.

As specified here _spawn, _wspawn Functions, only the functions with a 'p' letter in the name implicitely use the PATH environment variable. The others don't.

So you need to do this:

char *args[] =  {"notepad.exe", NULL };
_spawnvpe(_P_NOWAIT, args[0], args, NULL);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!