Q:show output from script

Discussion in 'C++' started by R. Stormo, Jan 9, 2005.

  1. R. Stormo

    R. Stormo Guest

    I have a problem showing output that is comming from a script.
    If I make a script running at commandline it do work and everything
    are showing.
    But when I try to execute it from within my proggy it would not show.
    I have tried to save the outout to a file and again, when I runit from
    commandline it do save everything but from software it would not.
    It do only show things that are outputed with "echo"

    My routine for showing the file are, the execute script rutine are the same.

    FILE *fp; //The filePIPE
    char message[1024]; //Declare buffer to hold the file
    fp = fopen( myfilename, "r" );//Read read in txt mode
    if ( fp==NULL )
    msgbox("could not open file to read !!!", "Warning");//Show File not
    found!
    else
    {
    while( !feof( fp ) ) //check for EOF
    {
    fgets( line, 128, fp ); //Read 128 bytes
    strcat( message, line ); //Add this line to previous buffer
    }
    fclose(fp); //Close the filePIPE
    //------------------------------
    // Show the output in a dialogbox on screen
    //------------------------------
    eMessageBox msg(message, "OUTPUT", eMessageBox::iconInfo
    eMessageBox::btOK);
    msg.show(); msg.exec(); msg.hide();

    }



    In advance, thanks
     
    R. Stormo, Jan 9, 2005
    #1
    1. Advertising

  2. R. Stormo wrote:
    > I have a problem showing output that is comming from a script.
    > If I make a script running at commandline it do work and everything
    > are showing.
    > But when I try to execute it from within my proggy it would not show.
    > I have tried to save the outout to a file and again, when I runit from
    > commandline it do save everything but from software it would not.
    > It do only show things that are outputed with "echo"
    >
    > My routine for showing the file are, the execute script rutine are the same.
    >
    > FILE *fp; //The filePIPE
    > char message[1024]; //Declare buffer to hold the file


    What happens if the file is bigger than 1024 bytes?


    > fp = fopen( myfilename, "r" );//Read read in txt mode
    > if ( fp==NULL )
    > msgbox("could not open file to read !!!", "Warning");//Show File not
    > found!
    > else
    > {
    > while( !feof( fp ) ) //check for EOF
    > {
    > fgets( line, 128, fp ); //Read 128 bytes
    > strcat( message, line ); //Add this line to previous buffer


    You should be checking the total bytes read to make sure
    you don't overflow the buffer.

    > }
    > fclose(fp); //Close the filePIPE
    > //------------------------------
    > // Show the output in a dialogbox on screen
    > //------------------------------
    > eMessageBox msg(message, "OUTPUT", eMessageBox::iconInfo
    > eMessageBox::btOK);
    > msg.show(); msg.exec(); msg.hide();
    >
    > }
    >
    >
    >
    > In advance, thanks


    This looks like a platform / operating system issue.
    Many windowing operating systems do not support the
    mixing of scripts and windowing. Does yours?

    Perhaps you should ask about this on a newsgroup
    dedicated to your platform.


    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.comeaucomputing.com/learn/faq/
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
    http://www.sgi.com/tech/stl -- Standard Template Library
     
    Thomas Matthews, Jan 9, 2005
    #2
    1. Advertising

  3. R. Stormo

    R. Stormo Guest

    Thomas Matthews wrote:

    > R. Stormo wrote:
    >
    > What happens if the file is bigger than 1024 bytes?
    >
    >
    >
    > You should be checking the total bytes read to make sure
    > you don't overflow the buffer.


    Dont worry about that in the first place. Best part first and that is to
    make it work :D

    It would never be over 1024 bytes.
    >>
    >>
    >> In advance, thanks

    >
    > This looks like a platform / operating system issue.
    > Many windowing operating systems do not support the
    > mixing of scripts and windowing. Does yours?
    >
    > Perhaps you should ask about this on a newsgroup
    > dedicated to your platform.

    Think my system with cope with it, I have seen it be done. It's a linux
    system.


    R. Stormo
     
    R. Stormo, Jan 9, 2005
    #3
  4. R. Stormo

    Mike Wahler Guest

    "R. Stormo" <anti_rohnny@spam_stormweb.no> wrote in message
    news:FjaEd.81749$...
    > I have a problem showing output that is comming from a script.
    > If I make a script running at commandline it do work and everything
    > are showing.
    > But when I try to execute it from within my proggy it would not show.
    > I have tried to save the outout to a file and again, when I runit from
    > commandline it do save everything but from software it would not.
    > It do only show things that are outputed with "echo"
    >
    > My routine for showing the file are, the execute script rutine are the

    same.
    >
    > FILE *fp; //The filePIPE
    > char message[1024]; //Declare buffer to hold the file


    This is an array of uninitalized characters.

    > fp = fopen( myfilename, "r" );//Read read in txt mode
    > if ( fp==NULL )
    > msgbox("could not open file to read !!!", "Warning");//Show File not
    > found!


    There's no function 'msgbox()' in standard C. If it's your
    function, you need to show its definition. OTherwise when
    posting here, use a standard function, e.g.:

    puts("could not open file to read !!!");

    > else
    > {
    > while( !feof( fp ) ) //check for EOF


    You're using 'feof()' incorrectly. See the C FAQ for details.

    > {
    > fgets( line, 128, fp ); //Read 128 bytes


    You should check the return value of 'fgets()' to see if
    an error occurred.

    > strcat( message, line ); //Add this line to previous buffer


    'strcat()' will attempt to evaluate the value of the first
    character of the array 'message'. Since it has never been
    initialized or given a valid value, this produces undefined
    behavior.

    > }
    > fclose(fp); //Close the filePIPE
    > //------------------------------
    > // Show the output in a dialogbox on screen
    > //------------------------------
    > eMessageBox msg(message, "OUTPUT", eMessageBox::iconInfo
    > eMessageBox::btOK);
    > msg.show(); msg.exec(); msg.hide();
    >
    > }


    -Mike
     
    Mike Wahler, Jan 9, 2005
    #4
  5. R. Stormo

    R. Stormo Guest

    Mike Wahler wrote:

    >


    >
    > There's no function 'msgbox()' in standard C. If it's your
    > function, you need to show its definition. OTherwise when
    > posting here, use a standard function, e.g.:

    The messagebox.c
    void msgbox(char *mytekst, char *mytitle)
    {
    eMessageBox msg(mytekst, mytitle, eMessageBox::iconInfo|eMessageBox::btOK);
    msg.show(); msg.exec(); msg.hide();
    }

    there is not here the problem is.


    >
    > puts("could not open file to read !!!");
    >
    >> else
    >> {
    >> while( !feof( fp ) ) //check for EOF

    >
    > You're using 'feof()' incorrectly. See the C FAQ for details.
    >
    >> {
    >> fgets( line, 128, fp ); //Read 128 bytes

    >
    > You should check the return value of 'fgets()' to see if
    > an error occurred.
    >
    >> strcat( message, line ); //Add this line to previous buffer

    >
    > 'strcat()' will attempt to evaluate the value of the first
    > character of the array 'message'. Since it has never been
    > initialized or given a valid value, this produces undefined
    > behavior.

    thanks for info. As I have heard this is not the right way to execute a
    script either. But it does work. But it do only show the text that are
    written by echo and not what a command that are executeed within the script
    are printing out.

    If my script are like this.
    echo "telnet test"
    telnet someserver someport // this do output some text to screen
    echo "telnet test ending"

    If I run the script from commandline, it do show the right way. with text
    from telnet function.

    But If I use the routine it only shows what was written in echo. And it do
    execute the script.
    If I make a script with wget http://blabla/file_to_download

    this file are downloaded correctly into server.


    R. Stormo
     
    R. Stormo, Jan 9, 2005
    #5
  6. R. Stormo

    Mike Wahler Guest

    "R. Stormo" <anti_rohnny@spam_stormweb.no> wrote in message
    news:qEhEd.81846$...
    > Mike Wahler wrote:
    >
    > >

    >
    > >
    > > There's no function 'msgbox()' in standard C. If it's your
    > > function, you need to show its definition. OTherwise when
    > > posting here, use a standard function, e.g.:

    > The messagebox.c
    > void msgbox(char *mytekst, char *mytitle)
    > {
    > eMessageBox msg(mytekst, mytitle,

    eMessageBox::iconInfo|eMessageBox::btOK);
    > msg.show(); msg.exec(); msg.hide();
    > }
    >
    > there is not here the problem is.
    >
    >
    > >
    > > puts("could not open file to read !!!");
    > >
    > >> else
    > >> {
    > >> while( !feof( fp ) ) //check for EOF

    > >
    > > You're using 'feof()' incorrectly. See the C FAQ for details.
    > >
    > >> {
    > >> fgets( line, 128, fp ); //Read 128 bytes

    > >
    > > You should check the return value of 'fgets()' to see if
    > > an error occurred.
    > >
    > >> strcat( message, line ); //Add this line to previous buffer

    > >
    > > 'strcat()' will attempt to evaluate the value of the first
    > > character of the array 'message'. Since it has never been
    > > initialized or given a valid value, this produces undefined
    > > behavior.

    > thanks for info. As I have heard this is not the right way to execute a
    > script either.


    Standard C++ has no notion of 'scripts', so does not
    say anything about how to use them 'correctly'.

    > But it does work. But it do only show the text that are
    > written by echo and not what a command that are executeed within the

    script
    > are printing out.
    >
    > If my script are like this.
    > echo "telnet test"
    > telnet someserver someport // this do output some text to screen
    > echo "telnet test ending"


    None of that is C++ so not covered by this newsgroup.

    >
    > If I run the script from commandline, it do show the right way. with text
    > from telnet function.
    >
    > But If I use the routine it only shows what was written in echo. And it do
    > execute the script.
    > If I make a script with wget http://blabla/file_to_download
    >
    > this file are downloaded correctly into server.


    The closest thing to what you're asking about that C++ has
    is the 'std::system()' function (declared by header <cstdlib>
    (or <stdlib.h>), which passes a string to the host command
    processor (if one exists).

    e.g.

    std::system("some_command");

    The function is standard, but its argument is not.

    -Mike
     
    Mike Wahler, Jan 9, 2005
    #6
  7. R. Stormo

    R. Stormo Guest

    Mike Wahler wrote:

    >
    > "R. Stormo" <anti_rohnny@spam_stormweb.no> wrote in message
    >
    > The closest thing to what you're asking about that C++ has
    > is the 'std::system()' function (declared by header <cstdlib>
    > (or <stdlib.h>), which passes a string to the host command
    > processor (if one exists).

    This was to give you the hole picture of what that should be done.
    >
    > e.g.
    >
    > std::system("some_command");
    >
    > The function is standard, but its argument is not.


    Thanks, think this is what I was after.

    >
    > -Mike

    Have a nice day.
    R. Stormo
     
    R. Stormo, Jan 10, 2005
    #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. Matt

    TO show or NOT to show

    Matt, May 2, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    404
  2. Disco Octopus

    to show image or to show flash

    Disco Octopus, May 13, 2004, in forum: HTML
    Replies:
    7
    Views:
    2,450
    Toby A Inkster
    May 14, 2004
  3. Replies:
    1
    Views:
    605
    Evertjan.
    Sep 30, 2005
  4. Replies:
    1
    Views:
    188
    Evertjan.
    Sep 30, 2005
  5. John B. Matthews
    Replies:
    0
    Views:
    776
    John B. Matthews
    Dec 9, 2011
Loading...

Share This Page