system question

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

    #1

    system question

    I'm writing a little c program and one of things I'm trying to get it to do
    is cd to a particular directory and then run an exe that is on my path, as
    follows...

    strcpy(working_ string, "c:\\davedata\\ bats\\ks.exe fnord");
    system("cd \\playtime\\d\\ build\\html");
    system(working_ string);

    But ks.exe does not seem to be invoked on the files in the
    \\playtime\\d\\ build\\html directory.

    Can someone tell me how to do this?


  • Jens.Toerring@physik.fu-berlin.de

    #2
    Re: system question

    David Schwartz <david_vcp@hotm ail.com> wrote:[color=blue]
    > I'm writing a little c program and one of things I'm trying to get it to do
    > is cd to a particular directory and then run an exe that is on my path, as
    > follows...[/color]
    [color=blue]
    > strcpy(working_ string, "c:\\davedata\\ bats\\ks.exe fnord");
    > system("cd \\playtime\\d\\ build\\html");
    > system(working_ string);[/color]
    [color=blue]
    > But ks.exe does not seem to be invoked on the files in the
    > \\playtime\\d\\ build\\html directory.[/color]
    [color=blue]
    > Can someone tell me how to do this?[/color]

    The first invocation of system() creates a shell in which you do the 'cd'.
    Then the shell exits. As the next step you invoke a completely new shell
    by calling system() again that has no idea about the working directory of
    the other shell that's already dead. Execute both commands in the _same_
    call of system().
    Regards, Jens
    --
    \ Jens Thoms Toerring ___ Jens.Toerring@p hysik.fu-berlin.de
    \______________ ____________ http://www.toerring.de

    Comment

    • Dan Pop

      #3
      Re: system question

      In <c5j8k0$2c9dm$1 @uni-berlin.de> Jens.Toerring@p hysik.fu-berlin.de writes:
      [color=blue]
      >David Schwartz <david_vcp@hotm ail.com> wrote:[color=green]
      >> I'm writing a little c program and one of things I'm trying to get it to do
      >> is cd to a particular directory and then run an exe that is on my path, as
      >> follows...[/color]
      >[color=green]
      >> strcpy(working_ string, "c:\\davedata\\ bats\\ks.exe fnord");
      >> system("cd \\playtime\\d\\ build\\html");
      >> system(working_ string);[/color]
      >[color=green]
      >> But ks.exe does not seem to be invoked on the files in the
      >> \\playtime\\d\\ build\\html directory.[/color]
      >[color=green]
      >> Can someone tell me how to do this?[/color]
      >
      >The first invocation of system() creates a shell in which you do the 'cd'.
      >Then the shell exits. As the next step you invoke a completely new shell
      >by calling system() again that has no idea about the working directory of
      >the other shell that's already dead. Execute both commands in the _same_
      >call of system().[/color]

      And if your shell doesn't allow this directly, build a script
      containing the two commands and execute that script with system().

      Dan
      --
      Dan Pop
      DESY Zeuthen, RZ group
      Email: Dan.Pop@ifh.de

      Comment

      • CBFalconer

        #4
        Re: system question

        David Schwartz wrote:[color=blue]
        >
        > I'm writing a little c program and one of things I'm trying to
        > get it to do is cd to a particular directory and then run an exe
        > that is on my path, as follows...
        >
        > strcpy(working_ string, "c:\\davedata\\ bats\\ks.exe fnord");
        > system("cd \\playtime\\d\\ build\\html");
        > system(working_ string);
        >
        > But ks.exe does not seem to be invoked on the files in the
        > \\playtime\\d\\ build\\html directory.
        >
        > Can someone tell me how to do this?[/color]

        Not here. The C language has neither directories nor exes nor
        paths. You want a group dealing with your peculiar system, which
        I suspect to be either Windows or MsDos.

        --
        Chuck F (cbfalconer@yah oo.com) (cbfalconer@wor ldnet.att.net)
        Available for consulting/temporary embedded and systems.
        <http://cbfalconer.home .att.net> USE worldnet address!

        Comment

        Working...