Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <tchar.h>
- #include <fcntl.h>
- #include <io.h>
- #include <stdio.h>
- #define MAX 256
- using namespace std;
- //Permitir que o mesmo código possa funcionar para ASCII ou UNICODE
- #ifdef UNICODE
- #define tcout wcout
- #define tcin wcin
- #define tstring wstring
- #else
- #define tcout cout
- #define tcin cin
- #define tstring string
- #endif
- int _tmain(int argc, LPTSTR argv[]) {
- TCHAR fileN[MAX], str[MAX], numS[MAX], rec[MAX];
- int numI = -1;
- PROCESS_INFORMATION infoProcesso;
- STARTUPINFO infoSup;
- ZeroMemory(&infoSup, sizeof(infoSup));
- //UNICODE: Por defeito, a consola Windows não processe caracteres wide.
- //A maneira mais fácil para ter esta funcionalidade é chamar _setmode:
- #ifdef UNICODE
- _setmode(_fileno(stdin), _O_WTEXT);
- _setmode(_fileno(stdout), _O_WTEXT);
- #endif
- //5.a)
- /*GetModuleFileName(NULL, fileN, MAX);
- _tprintf(TEXT("%s\n\n"), fileN);
- fflush(stdin);*/
- //5.b/c)
- /*_tprintf(TEXT("Programa: "));
- _fgetts(str, MAX, stdin);
- str[_tcslen(str) - 1] = '\0';
- CreateProcess(NULL, str, NULL, NULL, 0, 0, NULL, NULL, &infoSup, &infoProcesso);
- _tprintf(TEXT("\n"));*/
- //5.d)
- if (argc >= 2) {
- numI = _tstoi(argv[1]) - 1;
- _stprintf_s(numS, MAX - 1, TEXT(" %d"), numI);
- GetModuleFileName(NULL, fileN, MAX);
- _tcscpy_s(rec, MAX, fileN);
- _tcscat_s(rec, MAX, numS);
- _tprintf(TEXT("\n--Número: %d\n"), numI);
- }
- if (numI > 0) {
- CreateProcess(NULL, rec, NULL, NULL, 0, 0, NULL, NULL, &infoSup, &infoProcesso);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement