System cmds

Discussion in 'C Programming' started by Profetas, Jun 12, 2004.

  1. Profetas

    Profetas Guest

    How can I use shell cmds with vars?
    I would like to execute
    system("cd var_path");
    where the var_path is a variable that has the path.
    is there any other way that enables me to use vars?


    thanks
     
    Profetas, Jun 12, 2004
    #1
    1. Advertising

  2. in comp.lang.c i read:

    >How can I use shell cmds with vars?
    >I would like to execute
    >system("cd var_path");
    >where the var_path is a variable that has the path.
    >is there any other way that enables me to use vars?


    build the string you want first. sprintf may be useful to you for that.

    --
    a signature
     
    those who know me have no need of my name, Jun 12, 2004
    #2
    1. Advertising

  3. Profetas

    tweak Guest

    Profetas wrote:
    > How can I use shell cmds with vars?
    > I would like to execute
    > system("cd var_path");
    > where the var_path is a variable that has the path.
    > is there any other way that enables me to use vars?
    >
    >
    > thanks
    >

    You question is OS specific, and as I have been told,
    is off topic for this list, which appears to dig deep
    into ISO C99:

    http://www.open-std.org/jtc1/sc22/wg14/

    which is OS independent.

    Nevertheless, if you are talking about a executing a file,
    here's the best example I could find for Unix:

    http://www.gnu.org/software/libc/ma...reation-Example.html#Process Creation Example

    Read up from the example. It explains all the types and functions.

    If you want to learn more about your computer, mudge wrote a great
    article on creating a buffer overflow that shows the use of an exec()
    function and then converts it to assembly and finally to op codes. It
    a great read if you want to learn more about how instructions are executed.

    Here's a link to that article:

    http://www.insecure.org/stf/mudge_buffer_overflow_tutorial.html

    I do not code windows, so I don't have a clue as to how to help you there.

    Cheers,

    Brian
     
    tweak, Jun 12, 2004
    #3
  4. "those who know me have no need of my name" <>
    wrote in message news:...
    > in comp.lang.c i read:
    >
    > >How can I use shell cmds with vars?
    > >I would like to execute
    > >system("cd var_path");
    > >where the var_path is a variable that has the path.
    > >is there any other way that enables me to use vars?

    >
    > build the string you want first. sprintf may be useful to you for that.


    system() probably won't do what you want it to do either. The system()
    function forks a child process, which I believe then runs your shell, which
    then runs your command such as "cd". This will result in no change of
    working directory for the parent process (which is probably what you're
    trying to achieve). Try looking for the chdir() function in the standard C
    library, this probably does do what you want.

    >
    > --
    > a signature
     
    Kieran Simkin, Jun 12, 2004
    #4
  5. "Kieran Simkin" <> writes:
    > "those who know me have no need of my name" <>
    > wrote in message news:...
    > > in comp.lang.c i read:
    > >
    > > >How can I use shell cmds with vars?
    > > >I would like to execute
    > > >system("cd var_path");
    > > >where the var_path is a variable that has the path.
    > > >is there any other way that enables me to use vars?

    > >
    > > build the string you want first. sprintf may be useful to you for that.

    >
    > system() probably won't do what you want it to do either. The system()
    > function forks a child process, which I believe then runs your shell, which
    > then runs your command such as "cd". This will result in no change of
    > working directory for the parent process (which is probably what you're
    > trying to achieve). Try looking for the chdir() function in the standard C
    > library, this probably does do what you want.


    The terms "fork", "child process", "shell", and "working directory"
    are all system-specific. There is no chdir() function in the standard
    C library, though there may be such a function in some system-specific
    (POSIX?) library.

    <OT>I think your answer would be correct in comp.unix.programmer.</OT>

    --
    Keith Thompson (The_Other_Keith) <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.
     
    Keith Thompson, Jun 12, 2004
    #5
  6. Profetas

    Malcolm Guest

    "tweak" <> wrote in message
    > > How can I use shell cmds with vars?
    > > I would like to execute
    > > system("cd var_path");
    > > where the var_path is a variable that has the path.
    > > is there any other way that enables me to use vars?
    > >
    > >

    > You question is OS specific, and as I have been told,
    > is off topic for this list, which appears to dig deep
    > into ISO C99:
    >

    Actaully this one is on-topic. The details of the the "cd" command are
    off-topic, of course, it may be a compact disk burner or a dc current
    inverter for all we care, but how to pass a command line to "system" is
    topical enough.
     
    Malcolm, Jun 12, 2004
    #6
  7. "Malcolm" <> writes:
    > "tweak" <> wrote in message
    > > > How can I use shell cmds with vars?
    > > > I would like to execute
    > > > system("cd var_path");
    > > > where the var_path is a variable that has the path.
    > > > is there any other way that enables me to use vars?
    > > >
    > > >

    > > You question is OS specific, and as I have been told,
    > > is off topic for this list, which appears to dig deep
    > > into ISO C99:
    > >

    > Actaully this one is on-topic. The details of the the "cd" command are
    > off-topic, of course, it may be a compact disk burner or a dc current
    > inverter for all we care, but how to pass a command line to "system" is
    > topical enough.


    Agreed, but the question of whether system("cd var_path") will do what
    you expect it to is system-specific and off-topic. (On Unix-like
    systems, it will have no effect on the current process; on other
    systems, I have no ides.)

    --
    Keith Thompson (The_Other_Keith) <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.
     
    Keith Thompson, Jun 12, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sfunds sfunds
    Replies:
    9
    Views:
    8,786
  2. Charles A. Lackman

    Streaming with System.IO and System.Net

    Charles A. Lackman, Dec 8, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    586
    Richard Grimes [MVP]
    Jan 15, 2005
  3. Mark Miller
    Replies:
    1
    Views:
    1,119
    Mark Miller
    Jul 18, 2003
  4. Matt
    Replies:
    2
    Views:
    888
    Matt Getting
    Jul 24, 2003
  5. =?ISO-8859-1?Q?Sch=FCle_Daniel?=

    [exec cmd for cmd in cmds]

    =?ISO-8859-1?Q?Sch=FCle_Daniel?=, Mar 8, 2006, in forum: Python
    Replies:
    3
    Views:
    415
    Scott David Daniels
    Mar 8, 2006
Loading...

Share This Page