Skip to main content
gamedev.net
🔒 Locked

weird problem using system()

Started by mayonaise Nov 1, 2004 at 1:09 PM 6 replies 500+ views
Original Post
mayonaise
mayonaise
i've written a simple MFC GUI application that allows the user to change a bunch of settings, then click "launch." this will call the system() command to run an external executable with command line arguments. the GUI app remains open after the external program finishes so you can launch it again if you want. my problem is that upon logging into windows, the FIRST time i run the GUI and press launch, the external program just locks up. the external program is a simple directx program. when it's launched from the GUI for the first time, the whole screen turns black as if the resolution is about to be changed and the program executed. but instead, the hourglass cursor appears, and nothing happens. i have to manually exit the directx program, which brings up a program error message box asking if i want to send an error report. after the first time launching the program from the GUI, it works perfectly fine until i log off or restart. if i just run the directx program on it's own, it also works fine the first time. if i exit the GUI and run it again, everything still works fine. i'm calling _flushall() before i call system. i'm really confused by this problem. i'm not sure if it happens on all machines, but so far i believe it does. what can i be doing wrong??
tHiSiSbOb
tHiSiSbOb
Hard to say what it might be without some code...For all we know, it could simply be some weirdness on your computer. Try to post the code and both of the compiled programs so that we can see if it is only a problem on your computer and if we can fix it.
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
mayonaise
mayonaise
here's a zip file containing both programs.
http://www.toastd.com/code/scroller.zip

the GUI can take bitmaps for foreground and background.. i don't have all of the checks implemented yet, so don't input a foreground size that's bigger than the screen resolution, or it won't be displayed.

as for code, i'll work on getting a simplified version up..
mayonaise
mayonaise
this is what a simplified version of the GUI code looks like for clicking the "launch" button. i just implemented it in a separate dialog app using the app wizard.

it's using GRETA, microsoft's regular expression library:
http://research.microsoft.com/projects/greta/
i had a lot of trouble trying to use the boost::regex libraries, probably because i'm a beginner with visual studio and windows programming... so i used this because i got it to work, and it gets the job done.

the whole project (visual studio 7.1) is posted here:
http://www.toastd.com/code/guitest.zip
when you run this test, scroller2.exe from the previous zip file posted above must be in the same directory as the guitest executable!

void CguitestDlg::OnBnClickedOk(){	TCHAR szPath[256];	// get absolute path of execution for this program	GetModuleFileName(NULL, szPath, sizeof(szPath) / sizeof(TCHAR));	CString commandLine = szPath;	// format using regular expressions. system() command does not like certain characters, like ":" and "\"	commandLine = formatPath(commandLine);	// append "scroller2". scroller2.exe must be in same directory!!!	commandLine += "scroller2";	// enclose path to scroller2 in quotes, again for system() call in case of spaces in path	commandLine = "\"" + commandLine + "\" ";	_flushall();	// make sure we can find CMD	if (system(NULL))	{		// write command line output to edit box for debugging purposes		CEdit* cmd = (CEdit*)CDialog::GetDlgItem(IDC_EDIT_CMD);		cmd->SetWindowText(commandLine);		_flushall();		system(commandLine);	}}CString CguitestDlg::formatPath(CString path){	string escapedPath = path;	subst_results results;	// replace "\" with "/"	rpattern pat("\\", "/", GLOBAL | NOBACKREFS);	// replace colon with colon - don't ask me why, but this is necessary for system() call	rpattern patColon(":", ":", GLOBAL | NOBACKREFS);	// remove self from execution path	rpattern patExe("guitest.exe", "", GLOBAL | NOBACKREFS);	pat.substitute(escapedPath, results);	patColon.substitute(escapedPath, results);	patExe.substitute(escapedPath, results);	return escapedPath.c_str();}
Apocryphiliac
Apocryphiliac
Make sure that you're running your program with valid arguments. Try running the program yourself with the _exact_ same arguments that your GUI is generating and see if you get the same results. If that works, you could try writing a tiny test program that simply runs system() with the argument that your GUI gives you. This should help you to narrow down where the problem lies.
tHiSiSbOb
tHiSiSbOb
I got a 404 on that zip file...
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
mayonaise
mayonaise
Quote:
Original post by tHiSiSbOb
I got a 404 on that zip file...

try again, i just fixed it

Quote:
Original post by Apocryphiliac
Make sure that you're running your program with valid arguments. Try running the program yourself with the _exact_ same arguments that your GUI is generating and see if you get the same results. If that works, you could try writing a tiny test program that simply runs system() with the argument that your GUI gives you. This should help you to narrow down where the problem lies.

yeah, i did everything you mentioned already. the command line is correct, as i tried running it manually with the command line generated by the GUI app. remember, the problem only exists on the very first call to "system()" from the GUI app. all subsequent calls work perfectly fine. any attempt to run the directx program separately, whether from windows or from a command prompt work fine.

i did write a small test program that simply calls system() with NO additional arguments (this is supported by the directx program), and the results are the same (see my last post, which is about that exactly). i tried making system call something else, like "ping www.google.com" or just "cmd" and those seem to work fine.

in addition, i also downloaded a couple other direct draw samples, to see whether or not my program would launch those successfully on the first try. it did not. so there must be something with the initialization of directx.. something with the memory being provided by the system() call that conflicts with the directx setup? but why it only freezes on the first instantiation is really confusing.

also remember, this problem only occurs the first time i run the GUI app and launch the directx program from login. after the first failure, everything works fine until i restart or logoff.
mayonaise
mayonaise
noone?? still can't solve the problem...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.