| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"R. Stormo" |
| Date: |
09 Jan 2005 07:28:11 AM |
| Object: |
Q:show output from script |
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
.
|
|
| User: "Mike Wahler" |
|
| Title: Re: Q:show output from script |
09 Jan 2005 03:18:24 PM |
|
|
"R. Stormo" <anti_rohnny@spam_stormweb.no> wrote in message
news:FjaEd.81749$Vf.3693222@news000.worldonline.dk...
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
.
|
|
|
| User: "R. Stormo" |
|
| Title: Re: Q:show output from script |
09 Jan 2005 03:48:18 PM |
|
|
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
.
|
|
|
| User: "Mike Wahler" |
|
| Title: Re: Q:show output from script |
09 Jan 2005 04:30:31 PM |
|
|
"R. Stormo" <anti_rohnny@spam_stormweb.no> wrote in message
news:qEhEd.81846$Vf.3695005@news000.worldonline.dk...
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
.
|
|
|
| User: "R. Stormo" |
|
| Title: Re: Q:show output from script |
10 Jan 2005 01:40:52 AM |
|
|
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
.
|
|
|
|
|
|
|
| User: "Thomas Matthews" |
|
| Title: Re: Q:show output from script |
09 Jan 2005 12:48:59 PM |
|
|
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
.
|
|
|
| User: "R. Stormo" |
|
| Title: Re: Q:show output from script |
09 Jan 2005 01:09:21 PM |
|
|
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
.
|
|
|
|
|

|
Related Articles |
|
|