Message-ID: <36E42806.E16550BF@home.com> From: "Edward F. Sowell" Organization: @Home Network X-Mailer: Mozilla 4.02 [en]C-AtHome0402 (Win95; U) MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Weird behavior with spawnl() Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 114 Date: Mon, 08 Mar 1999 19:38:01 GMT NNTP-Posting-Host: 24.0.195.218 X-Complaints-To: abuse AT home DOT net X-Trace: news.rdc2.occa.home.com 920921881 24.0.195.218 (Mon, 08 Mar 1999 11:38:01 PDT) NNTP-Posting-Date: Mon, 08 Mar 1999 11:38:01 PDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com The files below show some pretty weird behavior with regard to spawning processes. One problem is executables created with DJGPP gcc cannot be launched with a spawn() (I've tried spawnl(), spawnlp(), and a couple more) from a MS VC++ compiled executable. That is, if both buildsolxx.cpp and tstCreateProcess.cpp are compiled/linked with MS VC++ tools, everything works as expected. However, if the launched program (buildsolxxx.exe) is created with DJGPP compiler/linker (e.g., using rhide), there is no error reported from spawnl(), but the process is not in fact executed... i.e., the buildsol.log file is not created, etc. Any idea what could cause such behavior? Another piece of the puzzle: In my actual program, of which the below is a fragment extracted to isolate the problem, buildsolver.exe needs to spawn a "make" program. If buildsolver is compiled with MS VC++, it will not work, apparently because the command line (in the spawnl() arg list) gets chopped at 126 characters. So it appears that MS and GNU tools are somewhat incompatible with respect to the way processes are created. In my situation, where my software (which needs to launch makes and compilation) is supposed to work with a range of C++ compilers, it means that I MUST compile buildsolver with gcc (so it can launch gmake), and on the other hand I MUST NOT compile buildsolver with gcc (or it cannot be lunched by my MCF Windows interface! Comments greatly appreciated Ed Sowell PS: I know some may dismiss this as "another example of MS stuff not working right," but OTOH everything works fine if only MS tools are used--- sowelled AT home DOT com --------- // buildsolxx.cpp #include #include int main(int argc, char** argv) { ofstream errLogFile("buildsol.log"); if (argc != 3) { errLogFile << "Usage:" << endl << endl << "BuildSolver " << endl; return -1; } errLogFile << "Starting buildsolver with " << argv[0] << " " << argv[1]<< " " << argv[2] << endl; cout << "Starting buildsolver with " << argv[0] << " " << argv[1]<< " " << argv[2] << endl; cerr << "Starting buildsolver with " << argv[0] << " " << argv[1]<< " " << argv[2] << endl; return 0; } ---------------------------- // tstCreateProcess.cpp #include #include #include #include #include int main( int argc, char *argv[]) { if (argc != 5) { cout<< " wrong # args" << endl; return 1; } _fileinfo =1; // pass open file info to spawn ofstream logFile(argv[4]); if (putenv ("DJGPP=f:\\djgpp\\djgpp.env")) { perror ("Could not set DJGPP"); exit (EXIT_FAILURE); } if (putenv ("LFN=Y")) { perror ("Could not set LFN"); exit (EXIT_FAILURE); } if (putenv ("PATH=f:\\dggpp\\bin;c:\\spark\\bin;c:\\windows\\command;k:\\sparkr~1\\builds~1\\testcr~1\\debug")) { perror ("Could not set PATH"); exit (EXIT_FAILURE); } char* var; if(var = getenv("DJGPP")) cout << "set DJGPP=[" << var << "]" << endl; if(var = getenv("LFN")) cout << "set LFN=[" << var << "]" << endl; cout << flush; cerr << flush; int spawnres = spawnl(P_WAIT, argv[1], argv[1], argv[2],argv[3], NULL); if (spawnres != 0) { cout << endl; perror("Spawn returned an error in buildsolver."); } return spawnres; }