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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem using embedded 'unix' command 2

Status
Not open for further replies.

edwards76

Programmer
Sep 24, 2003
5
IE
I'm not sure if this is a perl, apache or windows problem, or what. But I'm completely stuck, and I'd appreciate any thoughts you might have:

I'm having trouble using the cal command (it's the unix command ported to windows) in my perl file. I'm running Apache 2.0.47 along with cygwin on XP, and the cal command is from cygutils 1.2 (or possibly 2.1.something, I'm not sure).

cal works fine at the command prompt and also when I manually translate a perl file, using /usr/bin/perl, but when I try to browse to the same perl file when it's being hosted by my apache server (and I've used both Opera and IE), the cal command doesn't work.
(in other words, apache is producing different html code than /usr/bin/perl does.)

this code:

$cal = `cal $month $year`;
print "$cal";

yields no html output when using a browsed.

I've tried a whole bunch of other "unix" commands, like date and ls, etc, in the same manner, and they've all worked.

Any ideas what is going on?

Thanks,
Jim
 
Hello Jim,

Have you tried specifying the full path to cal? Something like this.

$cal = `c:/cygwin/cal $month $year`;

I just made up a path there because I don't have cygwin, you'll have to put the proper path in obviously.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Hi Jim,

You may need to wrap some HTTP headers around the output - otherwise the browser may think it is something other than HTML.

Try doing the following as a quick check:


$cal = `cal $month $year`;
print &quot;<HTML><BODY><PRE>$cal</PRE></BODY></HTML>&quot;;

If that fails, you should try using the CGI module and the header() function.

Scotty
 
Hi Mike,
Yeah, I have tried that--the weird thing is that when I use the entire path (c:\cygwin\bin\cal), the perl compiler at the command line breaks also. Not sure why that is, but I don't think it's related to my problem, because, as I said, a bunch of the other unix commands work fine without the entire path.

For example:

$date = `date`;
print &quot;$date&quot;;

produces this html:

Wed Sep 24 06:21:08 EST 2003

Any other ideas?

Thanks,
Lyn
 
Scotty,
I'm pretty sure that's not the problem.

Here's my test program:

#!/usr/bin/perl

use CGI qw:)standard :html3);

# unbuffered STDOUT
$|=1;
print header;

my ($a, $b);

$a = `cal 9 2003`;
$b = `date`;

print &quot;$a&quot;;
print &quot;<p>and then...<p>&quot;;
print &quot;$b&quot;;

____________________________________

Here's the HTML produced:

<p>and then...<p>Wed Sep 24 06:35:35 EST 2003

________________________________

And here's the output of /usr/bin/perl:

Content-Type: text/html; charset=ISO-8859-1

September 2003
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

<p>and then...<p>Wed Sep 24 06:37:10 EST 2003

__________________________________________

Any obvious problems?

Thanks,
Jim
 
Can you verify that you have any data in $a? i.e.

print length($a);

after all the other print statements.

I'd like to figure out if it is the browser not displaying the data correctly - or cal is failing to run correctly from the web server (environment problem?).

If you are really sad (like me), you can fire up netmon and look at the network traffic between you and the server and see if the data is there.

Scotty
 
Jim,

I'd follow Scott's lead in this kind of thing but one thing does occur to me. You're specifyin a path like this?

c:\cygwin\bin\cal

you should do this really

c:\\cygwin\\bin\\cal


Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Mike,
You're right about the path--thanks. Unfortunately, that doesn't fix the cal problem (it just makes the other unix commands work with the entire path).

Scotty,
I printed out the length of $a and it's 0.

This does sound like an environment problem, doesn't it? Any ideas where to poke around?

Thanks,
Jim
 
I had a problem recently where commands wouldn't work - I had to run the &quot;bash&quot; command first so that Windows knew to intepret the command as a unix command.

i.e. $cal = `bash c:/cygwin/bin/cal $month $year`;

Another thing you could try is to put the &quot;cal&quot; command into a batch file. Could try something like:-

print(BATCH, &quot;c:/cygwin/bin/cal $month $year\n&quot;);
close(BATCH);
$cal = `batch_file.bat`;

I've worked through a few of these recently and have had loads of difficulty doing this kind of thing.
 
I had a problem recently where commands wouldn't work - I had to run the &quot;bash&quot; command first so that Windows knew to intepret the command as a unix command.

i.e. $cal = `bash c:/cygwin/bin/cal $month $year`;

Another thing you could try is to put the &quot;cal&quot; command into a batch file. Could try something like:-

print(BATCH, &quot;c:\\cygwin\\bin\\cal $month $year\n&quot;);
close(BATCH);
$cal = `batch_file.bat`;

I've worked through a few of these recently and have had loads of difficulty doing this kind of thing.
 
In addition to dj's comments you might like to try running the command a couple of other ways:

open(CAL, &quot;c:\\cygwin\\bin\\cal $month $year|&quot;) or die;
while(<CAL>){
$a .= $_;
}

and the other method,

system(&quot;c:\\cygwin\\bin\\cal $month $year > a_text_file.txt&quot;);
open(F, &quot;a_text_file.txt&quot;) or die;
while(<F>){
$a .= $_;
}

There's More Than One Way To Do It, as someone or other once said.

Mike

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

It's like this; even samurai have teddy bears, and even teddy bears get drunk.
 
Great! I used the batch file technique, and it works like a charm (although I had to parse the output to get the exact string I was expecting).

Thanks so much to both of you--

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top