Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

executing program and reading program output to standard output

Status
Not open for further replies.

joezapp

Programmer
Feb 26, 2001
63
GB
Hi all,

Is it possible to something like the following using perl on sun Solaris ? Sorry if its a really idiotic question but I'm not too hot (just about tepid, if that) on perl -

1. Execute a program to output the results in standard output. ie something like system("/generate.exe -swf -yourswtfile.swt") ?

2. Catch the output (binary).

3. Write the content type:
("Content-Type: application/x-shockwave-flash\n")

4. Write the caught output to the standard output


Its possible using java but I've met a dead end there due to problems with my web server. Any pointers to tutorials or anything to give me a head start would be greatly appreciated.

Many thanx

Joe :)
 
Joe

I haven't used perl on the PC before, but in UNIX you can open a pipe to do this, for example:

Code:
#!/usr/bin/perl -w
open (INPUT, "ls -l |");
undef $/;
$input = <INPUT>;
close INPUT;
print &quot;$input&quot;;

So if pipes are simulated in Win-perl, you could try something like:

Code:
open (SHOCK, &quot;generate.exe -swf -yourswtfile.swt|&quot;);
undef $/;
binmode(SHOCK);     # might be needed?
$shock = <SHOCK>;
close SHOCK;
print qq(Content-type: application/x-shockwave-flash

$shock
);

Hope this helps. Sorry but as I say, I'm not that familiar with perl on windows :-( Cheers, NEIL
 
I don't see why not. I'm on Linux, not Sun, but that shouldn't make a difference.

You probably want to use backticks instead of &quot;system&quot; - backticks give the STDOUT of the thing being run back to the parent, like this:

@ls_lines = `ls -rlt`;

Once you have the output of the thing, then you can do whatever you want to with it, including outputtng HTML like you started to do - something like this:

@lines_of_output = `generate.exe -swf -yourswtfile.swt`;
print &quot;Content-Type: application/x-shockwave-flash\n\n&quot;;
print &quot;<pre>&quot;;
foreach (@lines_of_output) {
print <<EHTML;
$_
EHTML

print &quot;</pre>&quot;;

Of course this is completely untested - I'm sure you'll have to modify it(you'll need more html to start html, start body, finish body, finish html, etc.), but in theory it should work.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top