c++中怎么判断_tsystem()函数是否执行成功
https://blog.csdn.net/ghevinn/article/details/8650965
想用命令行的时候就使用_tsystem()这个函数,觉得挺简单,挺爽的。
可是越来越觉得有问题,
问题一:这个函数执行的命令行是否执行。
问题二:是否执行成功。
问题三:是否执行完成后正常退出。
Example #1
File: QueueUserWorkItemDemo.c Project: myd7349/Ongoing-Study
int _tmain(int argc, _TCHAR *argv[])
{
int i;
for (i = 0; i < 10; ++i)
{
if (!QueueUserWorkItem(ThreadProc, (LPVOID)i, WT_EXECUTEDEFAULT))
_ftprintf(stderr, _T("Failed to queue user worker item %d.\n"), i);
}
_putts(_T("Done!"));
Sleep(1000);
_putts(_T("-------------------------------------------------------------------------------"));
for (i = 10; i < 20; ++i)
{
if (!QueueUserWorkItem(ThreadProc, (LPVOID)i, WT_EXECUTEDEFAULT))
_ftprintf(stderr, _T("Failed to queue user worker item %d.\n"), i);
}
_tsystem(_T("pause"));
return 0;
}
Negative Edge and Positive Edge Exa...
Remaining Time -7:11
Negative Edge and Positive Edge Example Programming in PLC
Example #2
0
File: System.cpp Project: Rallymen007/StoreAppLauncher
void System::Shutdown( )
{
if( m_bBootExplorer )
{
_tsystem( _T( "taskkill /F /T /IM explorer.exe" ) );
TerminateProcess( m_hExplorer, 0 );
CloseHandle( m_hExplorer );
}
TerminateProcess( m_hProcess, 0 );
CloseHandle( m_hProcess );
CoUninitialize( );
}
Example #3
0
File: StaticTreeTest.cpp Project: ueverything/mmo-resourse
INT __fastcall MainCall(INT,LPTCHAR*)
{
_ENTER_FUN_C;
MSLOG.SetSaveLog(FALSE);
MSLOG.SetEnableLog(FALSE);
CMsStaticTree tree(50000, 20);
_tsystem(_T("pause"));
return 0;
_LEAVE_FUN_DISPOSE_END_C;
return INVALID_ID;
}
Example #4
0
File: main.cpp Project: myd7349/Ongoing-Study
int _tmain()
{
#ifdef _UNICODE
try {
std::locale::global(std::locale(""));
} catch (const std::runtime_error &exc) {
std::cout << exc.what() << std::endl;
}
#endif
_tcout << STR_GB2312 << std::endl;
dump(STR_GB2312);
// In Python 3.4.1:
/*
>>> str_utf8 = '海阔天空'.encode('utf-8')
>>> str_utf8
b'\xe6\xb5\xb7\xe9\x98\x94\xe5\xa4\xa9\xe7\xa9\xba'
>>> str_utf8.decode('gb2312')
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
str_utf8.decode('gb2312')
UnicodeDecodeError: 'gb2312' codec can't decode byte 0x98 in position 4: illegal multibyte sequence
>>> str_utf8.decode('gb18030')
'娴烽様澶╃┖'
>>> str_utf8.decode('cp936')
'娴烽様澶╃┖'
*/
_tcout << STR_UTF8_WITHOUT_BOM << std::endl;
dump(STR_UTF8_WITHOUT_BOM);
_tcout << STR_UTF8_WITH_BOM << std::endl;
dump(STR_UTF8_WITH_BOM);
#ifdef _MSC_VER
_tcout << STR_UTF16_BE << std::endl;
dump(STR_UTF16_BE);
_tcout << STR_UTF16_LE << std::endl;
dump(STR_UTF16_LE);
#endif
#ifdef _MSC_VER
_tsystem(_T("pause"));
#endif
return 0;
}
Example #5
0
File: CnHyperlink.cpp Project: sarrows/EasyCoding
void CnHyperlink::OnClicked()
{
bVisited_ = true;
CString str;
if (strUrl_.IsEmpty())
GetWindowText(str);
else
str = strUrl_;
if (bCmdMode_)
_tsystem(str);
else
ShellExecute(NULL, _T("open"), str, NULL, NULL, SW_SHOW);
Invalidate();
}
Example #6
0
File: TestLzma.cpp Project: Chrisso/Tests
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hFileIn = ::CreateFile(_T("C:\\Users\\Christoph\\Desktop\\S.csv.lzma"), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
HANDLE hFileOut = ::CreateFile(_T("C:\\Users\\Christoph\\Desktop\\S.csv.decd"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
BYTE header[LZMA_PROPS_SIZE + 8];
DWORD dwBytesRead = 0;
DWORD dwBytesWritten = 0;
::ReadFile(hFileIn, header, sizeof(header), &dwBytesRead, NULL);
ELzmaStatus status;
CLzmaDec state;
LzmaDec_Construct(&state);
LzmaDec_Allocate(&state, header, LZMA_PROPS_SIZE, &g_Alloc);
LzmaDec_Init(&state);
__int64 nSize = *reinterpret_cast<__int64*>(header + LZMA_PROPS_SIZE);
_tprintf(_T("Extracted size: %d\n"), nSize);
BYTE *pDataIn = new BYTE[BUFFER_SIZE];
BYTE *pDataOut = new BYTE[BUFFER_SIZE];
size_t nTotalSize = (size_t)nSize;
size_t nInSize = BUFFER_SIZE, nInPos = 0;
size_t nOutSize = BUFFER_SIZE;
while (nTotalSize)
{
if (!::ReadFile(hFileIn, pDataIn, BUFFER_SIZE, &dwBytesRead, NULL)) break;
if (dwBytesRead == 0) break;
nInSize = dwBytesRead;
nInPos = 0;
_tprintf(_T("."));
while (nInPos < nInSize)
{
size_t nInProcessed = nInSize - nInPos;
size_t nOutProcessed = BUFFER_SIZE;
LzmaDec_DecodeToBuf(&state, pDataOut, &nOutProcessed,
pDataIn + nInPos, &nInProcessed,
(nOutProcessed > nTotalSize)? LZMA_FINISH_END : LZMA_FINISH_ANY,
&status);
::WriteFile(hFileOut, pDataOut, nOutProcessed, &dwBytesRead, NULL);
nInPos += nInProcessed;
nTotalSize -= nOutProcessed;
if (nInProcessed == 0 && nOutProcessed == 0)
{
nInPos = nInSize = 0;
nTotalSize = 0;
}
}
}
delete[] pDataOut;
delete[] pDataIn;
LzmaDec_Free(&state, &g_Alloc);
::CloseHandle(hFileOut);
::CloseHandle(hFileIn);
#ifdef _DEBUG
_tsystem(_T("pause"));
#endif
return 0;
}
Example #7
0
File: windows.cpp Project: jwvg0425/OS_HomeWork
int CmdProcessing()
{
if (!_tcscmp(cmdTokenList[0], _T("exit"))){
return TRUE;
}
else if (!_tcscmp(cmdTokenList[0], _T("pwd")))
{
TCHAR cDIR[MAX_STR_LEN];
GetCurrentDirectory(MAX_STR_LEN, cDIR);
_tprintf(_T("%s\n"), cDIR);
}
else if (!_tcscmp(cmdTokenList[0], _T("cls")))
{
_tsystem(_T("cls"));
}
else if (!_tcscmp(cmdTokenList[0], _T("start")))
{
StartProcess(_T("windows"));
}
else if (!_tcscmp(cmdTokenList[0], _T("list")))
{
if (!PrintProcessList())
{
return -1;
}
}
else if (!_tcscmp(cmdTokenList[0], _T("cd")))
{
ChangeCurrentDirectory();
}
else if (!_tcscmp(cmdTokenList[0], _T("kill")))
{
if (!KillProcess())
{
return -1;
}
}
else if (!_tcscmp(cmdTokenList[0], _T("dir")))
{
if (!PrintFileList())
{
return -1;
}
}
else if (!_tcscmp(cmdTokenList[0], _T("mkdir")))
{
if (!MakeDirectory())
{
return -1;
}
}
else if (!_tcscmp(cmdTokenList[0], _T("rmdir")))
{
if (!RemoveDirectory())
{
return -1;
}
}
else if (!_tcscmp(cmdTokenList[0], _T("del")))
{
if (!DeleteFile())
{
return -1;
}
}
else if (!_tcscmp (cmdTokenList[0], _T("ren")))
{
if (!RenameFile())
{
return -1;
}
}
else if (!_tcscmp(cmdTokenList[0], _T("help")))
{
_tprintf(_T("pwd\t현재 디렉토리를 보여줍니다.\n"));
_tprintf(_T("cls\t화면을 지웁니다.\n"));
_tprintf(_T("help\t명령어 목록을 보여줍니다.\n"));
_tprintf(_T("exit\t프로그램을 종료합니다.\n"));
_tprintf(_T("echo\t문자열을 출력합니다.\n"));
_tprintf(_T("start\t프로그램을 실행합니다.\n"));
_tprintf(_T("list\t실햄중인 프로세스 목록을 보여줍니다.\n"));
_tprintf(_T("kill\t프로세스를 강제로 종료시킵니다. \n"));
_tprintf(_T("dir\t현재 디렉토리 하위의 파일 목록을 보여줍니다. \n"));
_tprintf(_T("mkdir\t현재 디렉토리 하위에 새 디렉토리를 생성합니다. \n"));
_tprintf(_T("rmdir\t현재 디렉토리 하위의 지정한 디렉토리를 삭제합니다. \n"));
_tprintf(_T("del\t현재 디렉토리 하위의 지정한 파일을 삭제합니다. \n"));
_tprintf(_T("ren\t현재 디렉토리 하위의 지정한 파일 이름을 변경합니다.\n"));
_tprintf(_T("cd\t현재 디렉토리를 변경합니다.\n"));
_tprintf(_T("history\t지금까지 입력한 명령어 목록을 보여줍니다.\n"));
_tprintf(_T("type\t파일의 내용을 화면에 출력합니다.\n"));
_tprintf(_T("sort\t입력한 문자열을 정렬하여 출력합니다.(Ctrl+Z로 종료)\n"));
_tprintf(_T("!(명령어)\t가장 최근에 수행한 (명령어)를 수행합니다.\n"));
_tprintf(_T("!!\t바로 전에 수행한 명령어를 실행합니다.\n"));
}
else if (!_tcscmp(cmdTokenList[0], _T("echo")))
{
EchoString();
}
else if (!_tcscmp(cmdTokenList[0], _T("type")))
{
TypeTextFile();
}
else if (!_tcscmp(cmdTokenList[0], _T("sort")))
{
SortString();
}
else if (!_tcscmp(cmdTokenList[0], _T("history")))
{
PrintHistory();
}
else
{
StartProcess(cmdTokenList[0]);
}
return 0;
}
Example #8
0
File: WlanHelper.cpp Project: nmap/npcap
int MainInteractive()
{
HANDLE hClient = NULL;
WLAN_INTERFACE_INFO sInfo[64];
RPC_TSTR strGuid = NULL;
TCHAR szBuffer[256];
DWORD dwRead;
if (OpenHandleAndCheckVersion(&hClient) != ERROR_SUCCESS)
{
_tsystem(_T("PAUSE"));
return -1;
}
UINT nCount = EnumInterface(hClient, sInfo);
for (UINT i = 0; i < nCount; ++i)
{
if (UuidToString(&sInfo[i].InterfaceGuid, &strGuid) == RPC_S_OK)
{
ULONG ulOperationMode = -1;
PULONG pOperationMode;
DWORD dwResult = GetInterface(wlan_intf_opcode_current_operation_mode, (PVOID*)&pOperationMode, &sInfo[i].InterfaceGuid);
if (dwResult != ERROR_SUCCESS)
{
_tprintf(_T("GetInterface error, error code = %d\n"), dwResult);
_tsystem(_T("PAUSE"));
}
else
{
ulOperationMode = *pOperationMode;
WlanFreeMemory(pOperationMode);
}
_tprintf(_T("%d. %s\n\tName: %s\n\tDescription: %s\n\tState: %s\n\tOperation Mode: %s\n"),
i,
strGuid,
getAdapterNameFromGuid((TCHAR*) strGuid).c_str(),
sInfo[i].strInterfaceDescription,
GetInterfaceStateString(sInfo[i].isState),
GetInterfaceOperationModeString(ulOperationMode));
RpcStringFree(&strGuid);
}
}
UINT nChoice = 0;
GUID ChoiceGUID;
LPGUID pChoiceGUID = NULL;
_tprintf(_T("Enter the choice (0, 1,..) of the wireless card you want to operate on:\n"));
if (ReadConsole(GetStdHandle(STD_INPUT_HANDLE), szBuffer, _countof(szBuffer), &dwRead, NULL) == FALSE)
{
_putts(_T("Error input."));
_tsystem(_T("PAUSE"));
return -1;
}
szBuffer[dwRead] = 0;
// TCHAR *aaa = _T("42dfd47a-2764-43ac-b58e-3df569c447da");
// dwRead = sizeof(aaa);
TCHAR buf[256];
_stprintf_s(buf, 256, _T("{%s}"), szBuffer);
if (dwRead > 32)
{
if (myGUIDFromString(buf, &ChoiceGUID) != TRUE)
{
_tprintf(_T("UuidFromString error, error code = %d\n"), -1);
_tsystem(_T("PAUSE"));
}
else
{
pChoiceGUID = &ChoiceGUID;
}
}
else
{
nChoice = _ttoi(szBuffer);
if (nChoice > nCount)
{
_putts(_T("No such index."));
_tsystem(_T("PAUSE"));
return -1;
}
pChoiceGUID = &sInfo[nChoice].InterfaceGuid;
}
UINT nSTate = 0;
ULONG ulOperationMode = -1;
_tprintf(_T("Enter the operation mode (0, 1 or 2) you want to switch to for the chosen wireless card:\n"));
_tprintf(_T("0: Extensible Station (ExtSTA)\n1: Network Monitor (NetMon)\n2: Extensible Access Point (ExtAP)\n"));
if (ReadConsole(GetStdHandle(STD_INPUT_HANDLE), szBuffer, _countof(szBuffer), &dwRead, NULL) == FALSE)
{
_putts(_T("Error input."));
_tsystem(_T("PAUSE"));
return -1;
}
szBuffer[dwRead] = 0;
nSTate = _ttoi(szBuffer);
if (nSTate != 0 && nSTate != 1 && nSTate != 2)
{
_putts(_T("Only 0, 1 and 2 are valid inputs."));
_tsystem(_T("PAUSE"));
return -1;
}
if (nSTate == 0)
{
ulOperationMode = DOT11_OPERATION_MODE_EXTENSIBLE_STATION;
}
else if (nSTate == 1)
{
ulOperationMode = DOT11_OPERATION_MODE_NETWORK_MONITOR;
}
else // nSTate == 2
{
ulOperationMode = DOT11_OPERATION_MODE_EXTENSIBLE_AP;
}
DWORD dwResult = SetInterface(wlan_intf_opcode_current_operation_mode, (PVOID*)&ulOperationMode, pChoiceGUID);
if (dwResult != ERROR_SUCCESS)
{
_tprintf(_T("SetInterface error, error code = %d\n"), dwResult);
_tsystem(_T("PAUSE"));
}
else
{
_tprintf(_T("SetInterface success!\n"));
}
return 0;
}
Example #9
0
File: cryptfile.cpp Project: Chrisso/Tools
int _tmain(int argc, _TCHAR* argv[])
{
if (sodium_init() == -1)
{
_tprintf(_T("Could not initialize cryptography subsystem!\n"));
return 1;
}
if (argc < 3)
{
_tprintf(_T("usage: cryptfile [-d] [-o <outfile>] <password> <file>\n"));
_tprintf(_T("where\n"));
_tprintf(_T("\t-o <outfile> filename for non inplace encryption\n"));
_tprintf(_T("\t-d decrypt file\n"));
return 1;
}
bool bDecrypt = false;
bool bUseTempFile = true;
TCHAR szSourceFile[MAX_PATH];
TCHAR szTargetFile[MAX_PATH];
for (int i = 1; i < argc - 2; i++)
{
if (_tcscmp(_T("-d"), argv[i]) == 0)
bDecrypt = true;
if (_tcscmp(_T("-o"), argv[i]) == 0)
{
_tcscpy_s(szTargetFile, MAX_PATH, argv[i + 1]);
bUseTempFile = false;
}
}
if (bUseTempFile)
{
_tcscpy_s(szTargetFile, MAX_PATH, argv[argc - 1]);
_tcscpy_s(szSourceFile, MAX_PATH, argv[argc - 1]);
_tcscat_s(szSourceFile, MAX_PATH, _T(".tmp"));
if (!::MoveFile(szTargetFile, szSourceFile))
{
_tprintf(_T("File access denied: %s\n"), szTargetFile);
return 1;
}
}
else
{
_tcscpy_s(szSourceFile, MAX_PATH, argv[argc - 1]);
}
unsigned char pKey[crypto_stream_KEYBYTES];
unsigned char pNonce[crypto_stream_NONCEBYTES];
unsigned char pSalt[crypto_pwhash_scryptsalsa208sha256_SALTBYTES];
// generate simple password salt (unique for this application)
for (size_t i = 2; i < crypto_pwhash_scryptsalsa208sha256_SALTBYTES; i++)
pSalt[i] = (i * 2) & 0xFF;
pSalt[0] = 'C';
pSalt[1] = 'S';
// generate key (derived from password)
crypto_pwhash_scryptsalsa208sha256(
pKey, sizeof(pKey),
reinterpret_cast<const char*>(argv[argc - 2]), _tcslen(argv[argc - 2]) * sizeof(TCHAR),
pSalt,
crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE,
crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE);
HANDLE hSourceFile = ::CreateFile(szSourceFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hSourceFile == INVALID_HANDLE_VALUE)
{
_tprintf(_T("File access denied: %s\n"), szSourceFile);
return 1;
}
HANDLE hTargetFile = ::CreateFile(szTargetFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hTargetFile == INVALID_HANDLE_VALUE)
{
::CloseHandle(hSourceFile);
_tprintf(_T("File access denied: %s\n"), szTargetFile);
return 1;
}
BYTE *pData = new BYTE[CHUNK_SIZE];
DWORD dwBytesRead = 0;
DWORD dwBytesWritten = 0;
if (bDecrypt)
{
// load file unique number for decryption
::ReadFile(hSourceFile, pNonce, sizeof(pNonce), &dwBytesRead, NULL);
}
else
{
// generate number to used once (unique for each file)
randombytes_buf(pNonce, sizeof(pNonce));
::WriteFile(hTargetFile, pNonce, sizeof(pNonce), &dwBytesWritten, NULL);
}
while (::ReadFile(hSourceFile, pData, CHUNK_SIZE, &dwBytesRead, NULL) && dwBytesRead > 0)
{
crypto_stream_xor(pData, pData, dwBytesRead, pNonce, pKey); // inplace
::WriteFile(hTargetFile, pData, dwBytesRead, &dwBytesWritten, NULL);
}
delete[] pData;
::CloseHandle(hTargetFile);
::CloseHandle(hSourceFile);
if (bUseTempFile)
::DeleteFile(szSourceFile);
#ifdef _DEBUG
_tsystem(_T("pause"));
#endif
return 0;
}