system() and no console ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bugs

    #1

    system() and no console ?

    I'm very new to C and am having a hard time figuring out how to pass a
    command to the underlying OS so as it doesn't keep the console window
    open. By double-clicking from Windows Explorer, I want the other
    process to just spawn and the console to close.

    For example, on Windows XP, I make the following call:

    system(my_comma nd);

    where my_command = 'my_program.exe '.
    But in Windows the console window stays open until my_program.exe exits.
    I guess that makes sense but how would I change my_command or is there
    an alternative to system() that would spawn a new process and then
    immediately return so my application can complete and close the console?
    I tried 'my_program.exe &', but that didnt work either.

    Thanks!
  • Walter Roberson

    #2
    Re: system() and no console ?

    In article <bdednXxsWIgFkH TfRVn-3g@comcast.com> , Bugs <dont@spam.me > wrote:[color=blue]
    >I'm very new to C and am having a hard time figuring out how to pass a
    >command to the underlying OS so as it doesn't keep the console window
    >open. By double-clicking from Windows Explorer, I want the other
    >process to just spawn and the console to close.[/color]

    Anything to do with underlying OS's and console windows is outside the
    scope of C itself. You should ask the question in a Windows newsgroup.
    --
    Look out, there are llamas!

    Comment

    • Bugs

      #3
      Re: system() and no console ?

      Walter Roberson wrote:[color=blue]
      >
      > Anything to do with underlying OS's and console windows is outside the
      > scope of C itself. You should ask the question in a Windows newsgroup.[/color]

      My apologies, I'll ask in the Windows newsgroup. I thought the answer
      might be an alternative C library call instead of system() ?
      Thanks

      Comment

      • Jack Klein

        #4
        Re: system() and no console ?

        On Thu, 28 Jul 2005 10:09:28 -0700, Bugs <dont@spam.me > wrote in
        comp.lang.c:
        [color=blue]
        > Walter Roberson wrote:[color=green]
        > >
        > > Anything to do with underlying OS's and console windows is outside the
        > > scope of C itself. You should ask the question in a Windows newsgroup.[/color]
        >
        > My apologies, I'll ask in the Windows newsgroup. I thought the answer
        > might be an alternative C library call instead of system() ?
        > Thanks[/color]

        Two things.

        Try the Windows group news:comp.os.ms-windows.program mer.win32, it is
        excellent and has a good traffic level and response rate.

        And there is no alternative standard C library call to system(). This
        is the one and only function that allows a C program to possibly
        interact with other executables. All others are non-standard,
        platform specific extensions. The methods you find for Windows will
        not work at all on Linux or a Macintosh.

        --
        Jack Klein
        Home: http://JK-Technology.Com
        FAQs for
        comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
        comp.lang.c++ http://www.parashift.com/c++-faq-lite/
        alt.comp.lang.l earn.c-c++

        Comment

        • Walter Roberson

          #5
          Re: system() and no console ?

          In article <MLudnfsubu_WjH TfRVn-vA@comcast.com> , Bugs <dont@spam.me > wrote:[color=blue]
          >Walter Roberson wrote:[/color]
          [color=blue][color=green]
          >> Anything to do with underlying OS's and console windows is outside the
          >> scope of C itself. You should ask the question in a Windows newsgroup.[/color][/color]
          [color=blue]
          >My apologies, I'll ask in the Windows newsgroup. I thought the answer
          >might be an alternative C library call instead of system() ?[/color]

          Sorry, doesn't exist.

          If it were Unix then there are techniques involving multiple shell levels
          and 'nohup' -- or better yet, POSIX extensions such as setsid()
          and O_NOCTTY when opening devices. But those are OS (or at least POSIX)
          specific, not part of C, and I have idea what the Windows paradigm would be.

          --
          "This was a Golden Age, a time of high adventure, rich living and
          hard dying... but nobody thought so." -- Alfred Bester, TSMD

          Comment

          • Bugs

            #6
            Re: system() and no console ?

            Thanks to everyone who responded.
            FYI - I found a workaround:
            As I'm passing system() a platform-specific WinXP command, I changed the
            command from 'myprogram.exe' to 'start myprogram.exe' and that worked
            fine. The console still pops up but for just an instant.
            Thanks again.

            Comment

            • Keith Thompson

              #7
              Re: system() and no console ?

              Bugs <dont@spam.me > writes:[color=blue]
              > Thanks to everyone who responded.
              > FYI - I found a workaround:
              > As I'm passing system() a platform-specific WinXP command, I changed
              > the command from 'myprogram.exe' to 'start myprogram.exe' and that
              > worked fine. The console still pops up but for just an instant.[/color]

              <COMPLETELY_O T>
              START /?
              prints a usage message that you might find illuminating.
              </COMPLETELY_OT>

              --
              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
              San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
              We must do something. This is something. Therefore, we must do this.

              Comment

              Working...