Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Q:show output from script

Reply
Thread Tools

Q:show output from script

 
 
R. Stormo
Guest
Posts: n/a
 
      01-09-2005
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
 
Reply With Quote
 
 
 
 
Thomas Matthews
Guest
Posts: n/a
 
      01-09-2005
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

 
Reply With Quote
 
 
 
 
R. Stormo
Guest
Posts: n/a
 
      01-09-2005
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

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

 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-09-2005

"R. Stormo" <anti_rohnny@spam_stormweb.no> wrote in message
news:FjaEd.81749$(E-Mail Removed) ...
> 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


 
Reply With Quote
 
R. Stormo
Guest
Posts: n/a
 
      01-09-2005
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
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      01-09-2005

"R. Stormo" <anti_rohnny@spam_stormweb.no> wrote in message
news:qEhEd.81846$(E-Mail Removed) ...
> 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


 
Reply With Quote
 
R. Stormo
Guest
Posts: n/a
 
      01-10-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute a script from another script and other script does notdo busy wait. Rajat Python 3 01-08-2010 02:05 PM
RE: How to execute a script from another script and other script doesnotdo busy wait. VYAS ASHISH M-NTB837 Python 2 01-07-2010 08:18 PM
How to fetch output of some other script in the current running perl script? ritugoyal12@gmail.com Perl Misc 4 10-27-2007 03:52 PM
Is Fuji S3000 3.2m/pixel output, or 6 m/pixel interpolated output? Peter H Digital Photography 43 12-04-2003 02:35 PM
Output / Debug window output bug? John Bentley ASP .Net 0 09-10-2003 07:38 AM



Advertisments