system call in VC

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kaci_tizi_ouzou2000@yahoo.ca

    #1

    system call in VC

    Greetings all.

    I am trying to make a system call as on WinXP,

    #include <stdlib.h>

    int main()
    {
    system( "ls -al");
    }

    but it is doing nothing!!

    Has anybody ever experienced such a thing!? My belief is there is a
    library that was missed when I installed VC but I am not sure.

    Any suggestions, hints, pointers etc etc is greatly appreciated.

    Cheers

  • Richard Heathfield

    #2
    Re: system call in VC

    kaci_tizi_ouzou 2000@yahoo.ca said:
    [color=blue]
    > Greetings all.
    >
    > I am trying to make a system call as on WinXP,
    >
    > #include <stdlib.h>
    >
    > int main()
    > {
    > system( "ls -al");
    > }
    >
    > but it is doing nothing!!
    >
    > Has anybody ever experienced such a thing!? My belief is there is a
    > library that was missed when I installed VC but I am not sure.
    >
    > Any suggestions, hints, pointers etc etc is greatly appreciated.[/color]

    Firstly, check that your system has an ls command that accepts the switch
    -al. It is quite likely in your case that it does not, since ls isn't a
    command normally associated with Windows systems.

    Secondly, if your system does support an ls command, consider the
    possibility that the system call is executing so quickly that you simply
    don't see it. For example, consider doing something like:

    system("ls -al > listing.txt");

    and then checking for the existence of listing.txt.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999

    email: rjh at above domain (but drop the www, obviously)

    Comment

    • pete

      #3
      [ot]Re: system call in VC

      kaci_tizi_ouzou 2000@yahoo.ca wrote:[color=blue]
      >
      > Greetings all.
      >
      > I am trying to make a system call as on WinXP,
      >
      > #include <stdlib.h>
      >
      > int main()
      > {
      > system( "ls -al");
      > }
      >
      > but it is doing nothing!!
      >
      > Has anybody ever experienced such a thing!? My belief is there is a
      > library that was missed when I installed VC but I am not sure.
      >
      > Any suggestions, hints, pointers etc etc is greatly appreciated.[/color]

      Try replacing "ls -al" with "dir -al"

      --
      pete

      Comment

      • Richard Heathfield

        #4
        Re: [ot]Re: system call in VC

        pete said:
        [color=blue]
        > Try replacing "ls -al" with "dir -al"[/color]

        Are you *sure* dir takes -al? I'm not.

        --
        Richard Heathfield
        "Usenet is a strange place" - dmr 29/7/1999

        email: rjh at above domain (but drop the www, obviously)

        Comment

        • Simon Biber

          #5
          Re: [ot]Re: system call in VC

          pete wrote:[color=blue]
          > kaci_tizi_ouzou 2000@yahoo.ca wrote:[color=green]
          >>#include <stdlib.h>
          >>
          >>int main()
          >>{
          >> system( "ls -al");
          >>}
          >>
          >>but it is doing nothing!!
          >>
          >>Has anybody ever experienced such a thing!? My belief is there is a
          >>library that was missed when I installed VC but I am not sure.
          >>
          >>Any suggestions, hints, pointers etc etc is greatly appreciated.[/color]
          >
          >
          > Try replacing "ls -al" with "dir -al"[/color]

          Bad advice. The closest equivalent for "ls -al" is "dir /a".

          --
          Simon.

          Comment

          • Keith Thompson

            #6
            Re: [ot]Re: system call in VC

            Richard Heathfield <invalid@invali d.invalid> writes:[color=blue]
            > pete said:
            >[color=green]
            >> Try replacing "ls -al" with "dir -al"[/color]
            >
            > Are you *sure* dir takes -al? I'm not.[/color]

            It does if you have a file in the current directory named "-al".

            --
            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

            • abdur_rab7@yahoo.co.in

              #7
              Re: system call in VC

              Check whether the program has rihgts to execute the command attribute
              '-a'.

              Try giving the absolute path.

              Comment

              • Niklas Norrthon

                #8
                Re: system call in VC

                kaci_tizi_ouzou 2000@yahoo.ca writes:
                [color=blue]
                > Greetings all.
                >
                > I am trying to make a system call as on WinXP,
                >
                > #include <stdlib.h>
                >
                > int main()
                > {
                > system( "ls -al");
                > }
                >
                > but it is doing nothing!![/color]

                system() is part of the C standard, but it's effect depends entirely
                on the implementation, which means it's off topic here.

                Anyway, the system() function returns a value. Save that value, and
                read your implementation' s documentation to find out what it means.

                <OT>
                Last time I checked 'ls' wasn't a valid dos/windows command, so
                unless there is a file named ls.exe, ls.com, or ls.bat somewhere
                I'd expect the system call to fail.
                </OT>

                /Niklas Norrthon

                Comment

                • pete

                  #9
                  Re: [ot]Re: system call in VC

                  Keith Thompson wrote:[color=blue]
                  >
                  > Richard Heathfield <invalid@invali d.invalid> writes:[color=green]
                  > > pete said:
                  > >[color=darkred]
                  > >> Try replacing "ls -al" with "dir -al"[/color]
                  > >
                  > > Are you *sure* dir takes -al? I'm not.[/color]
                  >
                  > It does if you have a file in the current directory named "-al".[/color]

                  That would have to be the case ;)

                  --
                  pete

                  Comment

                  • Keith Thompson

                    #10
                    Re: system call in VC

                    "abdur_rab7@yah oo.co.in" <abdur_rab7@yah oo.co.in> writes:[color=blue]
                    > Check whether the program has rihgts to execute the command attribute
                    > '-a'.
                    >
                    > Try giving the absolute path.[/color]

                    What program?

                    Please read <http://cfaj.freeshell. org/google/>.

                    --
                    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

                    • Emmanuel Delahaye

                      #11
                      Re: system call in VC

                      kaci_tizi_ouzou 2000@yahoo.ca a écrit :[color=blue]
                      > Greetings all.
                      >
                      > I am trying to make a system call as on WinXP,
                      >
                      > #include <stdlib.h>
                      >
                      > int main()
                      > {
                      > system( "ls -al");
                      > }
                      >
                      > but it is doing nothing!![/color]

                      I'm not surprised that the unix commands are not supported by the
                      Windows shell. Try this :

                      system( "dir");

                      also, you may need some pause to see the results :

                      system( "pause");

                      Note that this code is standard C (hence on-topic here), but is not
                      portable.

                      --
                      A+

                      Emmanuel Delahaye

                      Comment

                      Working...