jarsigner.exe
接受一个参数并将一些文本输出到控制台:
string command = "jarsigner.exe -verify test.jar";
system(command.c_str());
当我运行此代码时,会出现命令提示符窗口
它将jar is verified
或jar is unsigned
打印到控制台。
如何从控制台获取此结果字符串?
答案 0 :(得分:2)
答案 1 :(得分:2)
答案 2 :(得分:1)
您可以将stdout重定向到文件(jarsigner.exe> outfile.txt),然后使用perl或shell脚本等实用程序解析文件的内容。
或者,您可以使用dup,_open_osfhandle或freopen函数在应用程序中重定向stdout。
答案 3 :(得分:0)
我创建了新进程并将其stdout重定向到文本文件,它可以工作。
STARTUPINFO si;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sa;
HANDLE hOutFile;
ZeroMemory( &si, sizeof(si) );
ZeroMemory( &pi, sizeof(pi) );
ZeroMemory( &sa, sizeof(sa) );
si.cb = sizeof(si);
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES ;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = true;
// Create output file and get file handle
hOutFile = CreateFile ( TEXT(outFilePath.c_str()),
FILE_SHARE_WRITE,
0,
&sa, // provide SECURITY_ATTRIBUTES
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
// Assign StartInfo StdOutput to file handle
si.hStdOutput = hOutFile ;
LPTSTR szCmdline = TEXT( command.c_str() );
if( !CreateProcess( NULL, // No module name (use command line)
szCmdline, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
true, // Set handle inheritance to TRUE
0, // No creation flags
NULL, // Use parent's environment block
TEXT(jarSignerExeDir.c_str()), // Use jarSignerExeDir FOR starting directory
&si, // Pointer to STARTUPINFO structure
&pi ) // Pointer to PROCESS_INFORMATION structure
)
{
ShowMessage( "CreateProcess failed (%d).\n" + GetLastError() );
}
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, INFINITE );
// Close process,thread and file handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
CloseHandle(hOutFile);