computerex
Sep7-08, 01:20 PM
Hello. I am writing a simple application which allows you to run shell commands.
http://i37.photobucket.com/albums/e80/computerex/ntbso.png
This is the method I used:
void run(std::string cmd, HWND hDlg)
{
cmd = cmd + " >> ctoutput.txt";
system(cmd.c_str());
LoadFile(GetDlgItem(hDlg, IDC_EDIT_OUTPUT), "ctoutput.txt");
}
The user entered command is ran using the system() function, and the output is redirected to a file, the program reads the file and posts the output in the editbox. The problem is, the commands aren't run in one process. It seems system() creates a sub-process, and the process terminates upon running the command. Which makes commands such as, "cd" useless. Any workarounds for this?
http://i37.photobucket.com/albums/e80/computerex/ntbso.png
This is the method I used:
void run(std::string cmd, HWND hDlg)
{
cmd = cmd + " >> ctoutput.txt";
system(cmd.c_str());
LoadFile(GetDlgItem(hDlg, IDC_EDIT_OUTPUT), "ctoutput.txt");
}
The user entered command is ran using the system() function, and the output is redirected to a file, the program reads the file and posts the output in the editbox. The problem is, the commands aren't run in one process. It seems system() creates a sub-process, and the process terminates upon running the command. Which makes commands such as, "cd" useless. Any workarounds for this?