Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm Sender: cygwin-owner AT sourceware DOT cygnus DOT com Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com From: "Robert O. Morris" To: Cc: "Distributed Oceanographic Data Server" , "Robert Morris" Subject: System(command) call returns immediately, command still running Date: Mon, 19 Jul 1999 07:21:07 -0700 Message-ID: <000101bed1f1$f0eadd40$0301a8c0@hs.earthlink.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0002_01BED1B7.448C0540" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 Importance: Normal In-Reply-To: <19990716121329.3976.rocketmail@web115.yahoomail.com> X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 ------=_NextPart_000_0002_01BED1B7.448C0540 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hello Cygwin mailing list participants ! I have a problem with the cygwin run-time environment under a common circumstance and was hoping someone in the mailing list has some ideas regarding this. main() { system(command); } works fine, however when I run a similiar instruction from a dll accessed from a non-cygwin application - I can see the "command" run in the background even after the .dll code I invoked is over and done with. I think this is related to the problems I have using stdin, stdout, stderr and other general problems with the run-time environment in such a situation. The other problems, I re-coded to work around. This problem - I don't see the solution. Fork/exec() is not the way to go with me. Pipe() won't work if std* is unusuable. I think system() was my last option. I do have another work around, but it is such a hack it makes me choke and probably won't be practical. I want the run-time to know enough that when system(command) spawns command - it knows to wait until command finishes before returning. I've included the cmex script which contains the dll initialization code also. Thank You ! Rob Morris ------=_NextPart_000_0002_01BED1B7.448C0540 Content-Type: text/plain; name="cmex.txt" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="cmex.txt" #!bash # required import libraries IMPDEFS=3D"matlab.exe libmx.dll libmccmx.dll libmmfile.dll libmcc.dll = libmatlb.dll libmat.dll" # ***Fill in your path to libcygwin.a here (with no trailing slash)*** LIBPATH=3D/cygwin-b20/H-i586-cygwin32/i586-cygwin32/lib # ***Fill in your path to the matlab 5 root here (with no trailing = slash)*** MATLAB=3D/home/matlab # ***Fill in your path to place to store .def files generated by this = script LIBMEX=3D$MATLAB/bin/implibs # check for arguments if [ $# -lt 1 ]; then echo "usage: cmex [-cig5] source" exit fi debug=3D0 inline=3D0 type=3D-mno-cygwin arch=3Di686 while getopts cig5? v; do if [ "$v" =3D=3D "?" ]; then echo "usage: cmex [-cig5] source" echo " c : link to cygwin1.dll (default:mingw)" echo " i : inline array access" echo " g : include debug info" echo " 5 : optimize for pentium (default:686)" exit else case $v in (g) debug=3D1;; (i) inline=3D1;; (5) arch=3Di586;; (c) type=3D ;; esac fi done while [ $OPTIND -gt 1 ]; do shift OPTIND=3D$(($OPTIND - 1)) done # debug or what? if [ $debug -eq 1 ]; then gccopts=3D"-Wall -g $type" else gccopts=3D"-Wall -O6 $type -march=3D$arch -ffast-math -fstrict-aliasing = -malign-double -DDODS_DEBUG -DHAVE_CONFIG_H -DUSE_LIBGXX_INLINES = -DARCH_32BIT -DV4_COMPAT -I/home/rmorris/data/build/DODS/include = -I/home/matlab/extern/include = -I/home/rmorris/data/build/DODS/packages-2.17/include = -I/home/rmorris/data/build/DODS/packages-2.17/include/w3c = -I/usr/local/include" fi # inline array access? if [ $inline -eq 0 ]; then rcopts=3D else rcopts=3D"--define ARRAY_ACCESS_INLINING" gccopts=3D"$gccopts -DARRAY_ACCESS_INLINING" fi # source file name(s) source=3D$* base=3D${1%.*} objs=3D${*//%.*/.o} # Compile source file(s): echo "windres $rcopts -i $MATLAB/extern/include/mexversion.rc -o = mexversion.o" windres $rcopts -i $MATLAB/extern/include/mexversion.rc -o mexversion.o = || exit echo "gcc -c $gccopts -DMATLAB_MEX_FILE -I$MATLAB/extern/include = ${source}" gcc -c $gccopts -DMATLAB_MEX_FILE -I$MATLAB/extern/include ${source} || = exit # Create fixup.o which is needed to terminate the # import list and the relocation section in the dll. cat > fixup.c << EOF /* Copied from winsup/dcrt0.cc in the cygwin32 source distribution. */ asm(".section .idata\$3\n" ".long 0,0,0,0, 0,0,0,0"); /* Next one is needed to properly terminate the .reloc section in the = dll */ asm(".section .reloc\n" ".long 0,8"); EOF gcc -c $gccopts fixup.c # Create a very minimalist startup routine for the dll. # C copy of winsup/init.cc in the cygwin32 source distribution. cat > init.c << EOF #include #include extern void __main( void ); extern struct _reent *__imp_reent_data; extern void cygwin_crt0( void *mainFunc ); static struct Globals { HANDLE cygwinDLLEvent; HANDLE cygwinDLLThread; } G; static int MLXCygwinDLLCallback(int argc,char **argv) { __main(); /* Initialize C++ runtime ... */ G.cygwinDLLEvent =3D CreateEvent(NULL,FALSE,FALSE,NULL); WaitForSingleObject(G.cygwinDLLEvent,INFINITE); return 0; } static DWORD WINAPI initCygwinDLL(void *dummy) { cygwin_crt0(MLXCygwinDLLCallback); return 0; } int WINAPI dll_entry (HANDLE h, DWORD reason, void *ptr) { DWORD threadId; _impure_ptr =3D __imp_reent_data; switch (reason) { case DLL_PROCESS_ATTACH: G.cygwinDLLThread =3D CreateThread(NULL,0,initCygwinDLL,(void = *)NULL, 0,&threadId); SetThreadPriority(G.cygwinDLLThread,THREAD_PRIORITY_HIGHEST); break; case DLL_PROCESS_DETACH: PulseEvent(G.cygwinDLLEvent); break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } return 1; } EOF gcc -c $gccopts init.c # create import libraries if needed... # Note: # Dlltool release does not like .def files to start with a line = 'LIBRARY # '. Therefore this workaround: extract library name from line 1 # into variable libname and feed dlltool with a .def file with the = 1st # line stripped so the .def file starts with the line 'EXPORTS' IMPLIBS=3D if [ ! -d $LIBMEX ];then mkdir -p $LIBMEX fi for libname in ${IMPDEFS}; do if [ ! -f $LIBMEX/${libname%.*}.a ];then cd $MATLAB/bin echo "Creating $libname import library..." #mbs... tail +2l $MATLAB/extern/include/matlab.def > temp.def #mbs... if [ "$libname" =3D=3D "matlab.exe" ]; then tail +2l $MATLAB/extern/include/matlab.def > temp.def else echo "tail +2 $MATLAB/extern/include/${libname%.*}.def > temp.def" tail +2 $MATLAB/extern/include/${libname%.*}.def > temp.def fi #mbs... echo dlltool --def temp.def --dllname $libname --output-lib = $LIBMEX/${libname%.*}.a dlltool --def temp.def --dllname $libname --output-lib = $LIBMEX/${libname%.*}.a || exit rm temp.def cd - else echo "Will use existing import library $LIBMEX/${libname%.*}.a" fi IMPLIBS=3D"${IMPLIBS} $LIBMEX/${libname%.*}.a" done # Make .def file: echo EXPORTS > ${base}.def echo mexFunction >> ${base}.def # Link DLL. echo 'Linking DLL...' dllwrap -o ${base}.dll --def ${base}.def --entry _dll_entry AT 12 \ ${objs} init.o fixup.o mexversion.o ${IMPLIBS} $LIBPATH/libcygwin.a = /usr/local/lib/libcygipc.a /usr/local/lib/librpclib.a # Clean up rm ${base}.o init.c init.o fixup.c fixup.o mexversion.o ${base}.def ------=_NextPart_000_0002_01BED1B7.448C0540 Content-Type: text/plain; charset=us-ascii -- Want to unsubscribe from this list? Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com ------=_NextPart_000_0002_01BED1B7.448C0540--