translator.cpp
/*
 * Executes the shell command (cmd) and returns the shell output as a string
 */
Executes the shell command (cmd) and returns the shell output as a string
Executes the shell command ( cmd ) and returns the shell output as a string
wstring exec(const wchar_t* cmd) {
	char* utf8cmd = utf8string(cmd, (wcslen(cmd) + 1) * sizeof(wchar_t));
	array<wchar_t, 128> buffer;
	wstring result;
	while (1)
	{
		result = L"";
		shared_ptr<FILE> pipe(popen(utf8cmd, "r"), pclose);
		if (!pipe) {
			free(utf8cmd);
			throw runtime_error("popen() failed!");
		}
		while (!feof(pipe.get())) {
			if (fgetws(buffer.data(), 128, pipe.get()) != NULL)
				result += buffer.data();
		}
		if (result != L"Failed to establish network connection")
			break;
	}
	free(utf8cmd);
	return result;
}
wstring exec ( const wchar_t * cmd ) { char * utf8cmd = utf8string ( cmd , ( wcslen ( cmd ) + 1 ) * sizeof ( wchar_t ) ) ; array < wchar_t , 128 > buffer ; wstring result ; while ( 1 ) { result = L" " ; shared_ptr < FILE > pipe ( popen ( utf8cmd , " " ) , pclose ) ; if ( ! pipe ) { free ( utf8cmd ) ; throw runtime_error ( " " ) ; } while ( ! feof ( pipe . get ( ) ) ) { if ( fgetws ( buffer . data ( ) , 128 , pipe . get ( ) ) != NULL ) result += buffer . data ( ) ; } if ( result != L" " ) break ; } free ( utf8cmd ) ; return result ; }
Executes the shell command (cmd) and returns the shell output as a string
Executes the shell command ( cmd ) and returns the shell output as a string