home *** CD-ROM | disk | FTP | other *** search
/ CICA NT 1996 December / CICA_NT_CD-ROM_Walnut_Creek_December_1996.iso / util / bg.c < prev    next >
C/C++ Source or Header  |  1993-02-18  |  2KB  |  84 lines

  1. A crude port of xvi for Windows NT.  Pipes (e.g. reading to/from other
  2. processes) don't work, but otherwise it seems fully functional.
  3. The other files here are:
  4.  
  5.    xvi.exe - the executable
  6.    xvisrc.zip - the complete source and documentation.
  7.    xvidiff.zip - contains only the files I had to change for NT
  8.  
  9. xvi.exe will create a new window.  Normally the window in which you
  10. invoke xvi.exe will not be usable (because you won't be able to
  11. invoke anything else until xvi.exe exits).  You can use the program
  12. below to put it in the background (e.g. I have a batch file called vi.bat
  13. which essentially invokes "bg.exe xvi.exe %1").
  14.   
  15.          ...Tim Thompson...tjt@blink.att.com...
  16.  
  17. ---- cut here ----- ---- cut here ----- ---- cut here ----- ---- cut here ----
  18. /*
  19.  * bg - A utility for putting an NT program into the background.
  20.  *
  21.  * Intended to be compiled with a makefile like this:
  22.  *
  23.  * !include <ntwin32.mak>
  24.  *
  25.  * bg.exe:    bg.obj
  26.  *         $(link) $(conflags) -out:bg.exe bg.obj $(conlibs)
  27.  * 
  28.  * .c.obj:
  29.  *         $(cc) $(cflags) $(cvars) $*.c
  30.  */
  31.  
  32. #include <stdio.h>
  33. #include <fcntl.h>
  34. #include <winsock.h>
  35. #include <memory.h>
  36. #include <string.h>
  37. #include <io.h>
  38. #include <stdlib.h>
  39.  
  40. int Verbose = 0;
  41.  
  42. #define RCVSIZE 512
  43.  
  44. main(int argc,char **argv)
  45. {
  46.     char cmd[1024];
  47.     SECURITY_ATTRIBUTES saPipe; 
  48.     PROCESS_INFORMATION pi;
  49.     STARTUPINFO si;  /* for CreateProcess call */
  50.     int r, n;
  51.  
  52.     cmd[0] = '\0';
  53.     for ( n=1; n<argc; n++ ) {
  54.         strcat(cmd,argv[n]);
  55.         strcat(cmd," ");
  56.     }
  57.  
  58.     saPipe.nLength = sizeof(SECURITY_ATTRIBUTES);
  59.     saPipe.lpSecurityDescriptor = NULL;
  60.     saPipe.bInheritHandle = FALSE;
  61.  
  62.     memset(&si, 0, sizeof(si));
  63.     si.cb = sizeof(si);
  64.     r = CreateProcess(NULL,  /* filename */
  65.         cmd,  /* full command line for child */
  66.         NULL,  /* process security descriptor */
  67.         NULL,  /* thread security descriptor */
  68.         FALSE,  /* inherit handles? */
  69.         0,  /* creation flags */
  70.         NULL,  /* inherited environment address */
  71.         NULL,  /* startup dir; NULL = start in current */
  72.         &si,  /* pointer to startup info (input) */
  73.         &pi);  /* pointer to process info (output) */
  74.     if (!r) {
  75.         fprintf(stderr,"CreateProcess() failed");
  76.         return 1;
  77.     }
  78.     if ( Verbose )
  79.         fprintf(stderr,"CreateProcess for (%s) succeeded\n",cmd);
  80.     CloseHandle(pi.hThread);
  81.     CloseHandle(pi.hProcess);
  82.     return 0;
  83. }
  84.