windows平台,用system()调用的一个命令行程序,该命令行程序可能会执行错误,我想在执行system()后,判断该命令行程序的返回值. system()函数好像不可以。应该怎么写?那位大哥给个例子,十分感谢。
sprintf(cCmd,"utlrecv -f %s -h %s",FILEID1,HOSTNAME);
CreateProcess和GetExitCodeProcess应该怎么写?
參考答案:int system(char * command).函数调用成功则返回0,否则返回-1。
The CreateProcess function creates a new process and its primary thread. The new process runs the specified executable file in the security context of the calling process.
BOOL CreateProcess(
LPCTSTR lpApplicationName,
LPTSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCTSTR lpCurrentDirectory,
LPSTARTUPINFO lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);
The GetExitCodeProcess function retrieves the termination status of the specified process.
BOOL GetExitCodeProcess(
HANDLE hProcess,
LPDWORD lpExitCode
);
Parameters
hProcess
[in] Handle to the process.
The handle must have the PROCESS_QUERY_INFORMATION access right. For more information, see Process Security and Access Rights.
lpExitCode
[out] Pointer to a variable to receive the process termination status.
Return Values
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
具体情况请查看MSDN。
暂时没看出有什么问题。