Removing windows command line after execution

This is a discussion on Removing windows command line after execution within the C Programming forums, part of the General Programming Boards category; Is there any way to remove the command line after execution. For example, if you use the system function to ...

  1. #1
    Registered User redruby147's Avatar
    Join Date
    Sep 2008
    Location
    England
    Posts
    37

    Removing windows command line after execution

    Is there any way to remove the command line after execution. For example, if you use the system function to invoke another program, the cmd is left in the background blank. Is there a function like cmdclose() or something, I've had a search and I failed to come up with anything. Thanks

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    My understanding is this goes away automatically, unless you have a pause, or, the cmd window was open to start with.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    My understanding is this goes away automatically, unless you have a pause, or, the cmd window was open to start with.
    But if you use system() as he used in his example, your program waits for the other to finish before it closes it's command window.

    Instead of system(), I would use the spawn() family of functions - they spawn a separate process and once it's loaded your program continues as normal - closing the command window if that's when it ends.

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Quote Originally Posted by sean View Post
    But if you use system() as he used in his example, your program waits for the other to finish before it closes it's command window.
    Yes, certainly. I was assuming that.

    I use this same scenario from C to call Notepad and I reformat a file to < 72 chars per line. When I close Notepad, the cmd window goes away.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  5. #5
    Registered User redruby147's Avatar
    Join Date
    Sep 2008
    Location
    England
    Posts
    37
    Thanks, spawn seems to be what I'm looking for. I wrote this and i'm recieving error code -1, the file paths are relative, and all the files are in the correct location. Any ideas why it's giving that error?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <process.h>
    #include <windows.h>
    
    
    int main(void)
    {   
        int spawn_error_check;
        char eclipse[150];
        char *eclipse_ptr;
        eclipse_ptr = eclipse;
        /*Change these directories to match your setup*/
        sprintf(eclipse, "eclipse\\eclipse.exe -vm \\WINDOWS\\system32\\javaw.exe");
        spawn_error_check = spawnl(_P_NOWAIT, eclipse_ptr, NULL);
        if (spawn_error_check != 0)
        {
            fprintf(stderr,"Spawn error code: %d\n", spawn_error_check);
            system("pause");
            return 1;
        }             
        return 0;
    }
    Last edited by redruby147; 08-28-2009 at 06:48 AM.

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Code:
    sprintf(eclipse, "eclipse\\eclipse.exe -vm \\WINDOWS\\system32\\javaw.exe");
    spawn_error_check = spawnl(_P_NOWAIT, eclipse_ptr, NULL);
    The executable itself is one argument, and all the command line arguments are separate arguments after that. To signal the end of the arguments, you provide NULL as an argument, like so:

    Code:
    #include <process.h>
    
    int spawnl( int mode,
                const char * path, 
                const char * arg0, 
                const char * arg1..., 
                const char * argn, 
                NULL );
    So you would call:

    Code:
    spawnl(_P_NOWAIT, "eclipse\\eclipse\.exe", "-vm", "\\WINDOWS\\system32\\javaw.exe", "NULL);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Anyone using Windows 7?
    By Sharke in forum General Discussions
    Replies: 60
    Last Post: 07-12-2009, 09:05 AM
  2. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 03:55 PM
  3. Windows 2k Dos- Program Execution Time
    By maththeorylvr in forum C Programming
    Replies: 1
    Last Post: 03-17-2005, 10:03 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 01:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 06:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21