how to execute command and get it's result?

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

    how to execute command and get it's result?

    in perl
    we can execute command and get result(command line stdout) by

    $a=`cmdline parameter`;
    print $a;

    in c
    system('cmdline parameter');
    but i can not get the result (command line stdout).

    in c++?
    =============== =============== =============== ========
    have any standard method do this job?


  • Ian Collins

    #2
    Re: how to execute command and get it's result?

    sonet wrote:
    in perl
    we can execute command and get result(command line stdout) by
    >
    $a=`cmdline parameter`;
    print $a;
    >
    in c
    system('cmdline parameter');
    but i can not get the result (command line stdout).
    >
    Direct the output to a file and read the file.

    --
    Ian Collins.

    Comment

    • Spiros Bousbouras

      #3
      Re: how to execute command and get it's result?

      On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.co mwrote:
      sonet wrote:
      in perl
      we can execute command and get result(command line stdout) by
      >
      $a=`cmdline parameter`;
      print $a;
      >
      in c
      system('cmdline parameter');
      but i can not get the result (command line stdout).
      >
      Direct the output to a file and read the file.
      This of course assuming that whatever interprereter
      system() invokes supports redirections.

      Comment

      • sonet

        #4
        Re: how to execute command and get it's result?

        Yes!
        I can use system systemcall and direct the output to a file
        and read the file. May be it is like.

        system("cmdline parameter file");

        But if the program is cgi,we need generate a random filename.
        It may be a solution,but the method look very stupid.
        Have any other smart method to read the stdout from other command line?


        "Spiros Bousbouras" <spibou@gmail.c om>
        1182404061.2659 73.200270@w5g20 00...legro ups.com...
        On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.co mwrote:
        >sonet wrote:
        in perl
        we can execute command and get result(command line stdout) by
        >>
        $a=`cmdline parameter`;
        print $a;
        >>
        in c
        system('cmdline parameter');
        but i can not get the result (command line stdout).
        >>
        >Direct the output to a file and read the file.
        >
        This of course assuming that whatever interprereter
        system() invokes supports redirections.
        >

        Comment

        • Ian Collins

          #5
          Re: how to execute command and get it's result?

          sonet wrote:

          Please don't top-post.
          >
          "Spiros Bousbouras" <spibou@gmail.c om>
          1182404061.2659 73.200270@w5g20 00...legro ups.com...
          >On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.co mwrote:
          >>sonet wrote:
          >>>in perl
          >>>we can execute command and get result(command line stdout) by
          >>>$a=`cmdlin e parameter`;
          >>>print $a;
          >>>in c
          >>>system('cmdl ine parameter');
          >>>but i can not get the result (command line stdout).
          >>Direct the output to a file and read the file.
          >This of course assuming that whatever interprereter
          >system() invokes supports redirections.
          >>
          Yes!
          I can use system systemcall and direct the output to a file
          and read the file. May be it is like.
          >
          system("cmdline parameter file");
          >
          But if the program is cgi,we need generate a random filename.
          It may be a solution,but the method look very stupid.
          Have any other smart method to read the stdout from other command
          line?
          >
          There will be a better way, but it will be platform specific, so try the
          question on a group dedicated to your OS.

          --
          Ian Collins.

          Comment

          • !truth

            #6
            Re: how to execute command and get it's result?

            On 6 21 , 2 38 , Ian Collins <ian-n...@hotmail.co mwrote:
            sonet wrote:
            >
            Please don't top-post.
            >
            >
            >
            >
            >
            "Spiros Bousbouras" <spi...@gmail.c om>
            1182404061.2659 73.200...@w5g20 00hsg.googlegro ups.com...
            On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.co mwrote:
            >sonet wrote:
            >>in perl
            >>we can execute command and get result(command line stdout) by
            >>$a=`cmdline parameter`;
            >>print $a;
            >>in c
            >>system('cmdli ne parameter');
            >>but i can not get the result (command line stdout).
            >Direct the output to a file and read the file.
            This of course assuming that whatever interprereter
            system() invokes supports redirections.
            >
            Yes!
            I can use system systemcall and direct the output to a file
            and read the file. May be it is like.
            >
            system("cmdline parameter file");
            >
            But if the program is cgi,we need generate a random filename.
            It may be a solution,but the method look very stupid.
            Have any other smart method to read the stdout from other command
            line?
            >
            There will be a better way, but it will be platform specific, so try the
            question on a group dedicated to your OS.
            >
            --
            Ian Collins.- -
            >
            - -
            maybe you can use 'popen'

            Comment

            • Ian Collins

              #7
              Re: how to execute command and get it's result?

              !truth wrote:
              On 6 21 , 2 38 , Ian Collins <ian-n...@hotmail.co mwrote:
              >sonet wrote:
              >>"Spiros Bousbouras" <spi...@gmail.c om>
              >>1182404061.26 5973.200...@w5g 2000hsg.googleg roups.com...
              >>>On 21 Jun, 05:59, Ian Collins <ian-n...@hotmail.co mwrote:
              >>>>sonet wrote:
              >>>>>in perl
              >>>>>we can execute command and get result(command line stdout) by
              >>>>>$a=`cmdlin e parameter`;
              >>>>>print $a;
              >>>>>in c
              >>>>>system('cm dline parameter');
              >>>>>but i can not get the result (command line stdout).
              >>>>Direct the output to a file and read the file.
              >>>This of course assuming that whatever interprereter
              >>>system() invokes supports redirections.
              >>Yes!
              >>I can use system systemcall and direct the output to a file
              >>and read the file. May be it is like.
              >>system("cmdli ne parameter file");
              >>But if the program is cgi,we need generate a random filename.
              >>It may be a solution,but the method look very stupid.
              >>Have any other smart method to read the stdout from other command
              >>line?
              >There will be a better way, but it will be platform specific, so try the
              >question on a group dedicated to your OS.
              >>
              *Please* don't quote signatures.
              >
              maybe you can use 'popen'
              >
              Not if you OS doesn't have popen(), that's why I suggested a platform
              specific group.

              --
              Ian Collins.

              Comment

              • SM Ryan

                #8
                Re: how to execute command and get it's result?

                "sonet" <sonet.all@msa. hinet.netwrote:
                # in perl
                # we can execute command and get result(command line stdout) by
                #
                # $a=`cmdline parameter`;
                # print $a;
                #
                # in c
                # system('cmdline parameter');
                # but i can not get the result (command line stdout).
                #
                # in c++?
                # =============== =============== =============== ========
                # have any standard method do this job?

                Since the C standard doesn't even interpret the string in the
                system() call, you're out of luck with the C standard.

                Other standards provide additional methods, such as the
                popen in unix and some other systems. Unix also provides
                additional ways to redirect stdin, stdout, and stderr
                separately.

                Decide what systems you're willing to abandon and code
                to that standard.

                --
                SM Ryan http://www.rawbw.com/~wyrmwif/
                Who's leading this mob?

                Comment

                Working...