Q:show output from script

R

R. Stormo

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
 
T

Thomas Matthews

R. Stormo said:
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
 
R

R. Stormo

Thomas said:
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.
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
 
M

Mike Wahler

R. Stormo said:
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
 
R

R. Stormo

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 !!!");


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


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


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

Mike Wahler

R. Stormo said:
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.


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
 
R

R. Stormo

Mike said:
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.
Have a nice day.
R. Stormo
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top