Welcome Guest ( Log In | Click here to Register a free account now! )
Welcome to Bleeping Computer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.![]() ![]() |
May 11 2008, 12:02 AM
Post
#1
|
|
|
Big Brother is Watching You ![]() ![]() ![]() ![]() ![]() ![]() Group: HJT Senior Classmen Posts: 1,714 Joined: 17-January 08 From: Airstrip One Member No.: 184,215 |
Is there some fundimential thing about C++'s argument behavior I'm missing here? Here's what I'm currently doing: CODE char* getTextOfCommand(const char command[]){ //adds "> tempfile.txt" to the command string, executes it //reads the file to a string, deletes the file, and returns the string. char *holder; char *TempCharPTR; streamsize length; DWORD result; holder = new char[strlen(command)+40]; strcpy(holder,command); strcat(holder," > tempfile.txt"); ofstream tempfile("tempBat.bat",ios::trunc); tempfile << holder; tempfile.close(); delete [] holder; STARTUPINFOA si = { sizeof(STARTUPINFOA) }; si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE; PROCESS_INFORMATION pi; CreateProcessA(NULL,"cmd /C tempBat.bat",NULL,NULL,false,CREATE_NO_WINDOW,NULL,NULL,&si,&pi); do { GetExitCodeProcess(pi.hProcess,&result); Sleep(50); } while (result == STILL_ACTIVE); TerminateProcess(pi.hProcess,0); //needed because I will hang at program exit otherwise CloseHandle(pi.hProcess); CloseHandle(pi.hThread); Sleep(100); //give windows time to completely close the file before opening it std::ifstream file("tempfile.txt",std::ios::in); // //Get the length of the string // file.seekg(0,std::ios_base::end); length = file.tellg(); file.seekg(0,std::ios_base::beg); // //Allocate ram for buffer // holder = new char[length+1]; // 1 for the null term // //Dump the file to ram // TempCharPTR = holder; while (file.get(*TempCharPTR)) {TempCharPTR++; }; *TempCharPTR = '\0'; file.close(); //Delete the temp file Sleep(100); //make sure windows is done with the file from our last close before we delete it system("del /q /f tempfile.txt"); system("del /q /f tempBat.bat"); return holder; } Thanks, all! Billy3 -------------------- In the event I fail to reply within twenty-four hours, feel free to send me a PM.
Have I helped you? If so, please sign My Guestboox to help me get into college! Join BC.com's Folding Team (#38444)! Help Stanford University find a cure for diseases! ![]() |
|
|
|
![]() ![]() |
| Lo-Fi Version | Time is now: 5th July 2008 - 06:22 PM |