You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Wim Kerkhoff <wi...@merilus.com> on 2001/02/16 17:39:26 UTC

reading from files

Good morning/afternoon,

I've been trying to get a simple read from a pipe to work, but its not
doing what I'm intending. I'm using EmbperlObject ('cuz it rocks), but
get the same thing in just regular Embperl mode. My base.html is
extremely simple: just the look and a Execute('*') call.

So, Uptime 2 works below, but not Uptime 1 and Uptime 3.  What am I
doing wrong? It's gotta be something simple...


--------------------------------
Uptime 1:
 
[- open (UP, "uptime |") -]
 
[$ while ($line = (<UP>)) $]
  <b>[+ $line +]</b>
[$ endwhile $]
 
[- close (UP) -]

<br><br>
Uptime 2: [+ `uptime` +]

<br><br>
Uptime 3:
[-
  open (F, "uptime |");
  while (<F>) {
    print OUT $_;
  }
  close (F);
-]

---------------------------------

Wim

Re: reading from files

Posted by Wim Kerkhoff <wi...@merilus.com>.
Erdmut Pfeifer wrote:
> 
> On Fri, Feb 16, 2001 at 08:21:34PM +0100, Gerald Richter wrote:
> >
> > You should set either $optRawInput = 1 or use the backslash before the <UP>.
> > The error message looks like, you have used both. This will not work.
> >
> > BTW you could set EMBPERL_OPTIONS to 1 in your httpd.conf, if you write all
> > your code with an ascii editor, then you don't have to add it to all pages,
> > but you shouldn't do that in case you use some highlevel html editor.
> >
> > > that's strange... I have several code fragments like the following
> > > that work just as intended (they didn't wihout the "\<", however):
> > >
> >
> > Yes, this works with the backslash as longs as optRawInput isn't set
> 
> somehow, I could've sworn that I originally had tried $optRawInput
> and EMBPERL_OPTIONS before settling down to using the backlash
> method...
> So, just to see whether it was my stupidity, I checked it once again
> with a minimal test script -- and well, it obviously _was_ my fault, as
> it worked just fine now ;)  Don't know why it didn't work then -- I
> haven't yet tried to reproduce it under identical circumstances, though.
> Anyhow, if I should run into the same problem again, I'll report back :)

Thanks guys, it all works for me... shoulda tried a little harder first
I guess ;-)

-- 

Regards,

Wim Kerkhoff, Software Engineer
Merilus Technologies, Inc.
wim@merilus.com

Re: reading from files

Posted by Erdmut Pfeifer <e....@science-computing.de>.
On Fri, Feb 16, 2001 at 08:21:34PM +0100, Gerald Richter wrote:
> 
> You should set either $optRawInput = 1 or use the backslash before the <UP>.
> The error message looks like, you have used both. This will not work.
> 
> BTW you could set EMBPERL_OPTIONS to 1 in your httpd.conf, if you write all
> your code with an ascii editor, then you don't have to add it to all pages,
> but you shouldn't do that in case you use some highlevel html editor.
> 
> > that's strange... I have several code fragments like the following
> > that work just as intended (they didn't wihout the "\<", however):
> >
> 
> Yes, this works with the backslash as longs as optRawInput isn't set

somehow, I could've sworn that I originally had tried $optRawInput
and EMBPERL_OPTIONS before settling down to using the backlash
method...
So, just to see whether it was my stupidity, I checked it once again
with a minimal test script -- and well, it obviously _was_ my fault, as
it worked just fine now ;)  Don't know why it didn't work then -- I
haven't yet tried to reproduce it under identical circumstances, though.
Anyhow, if I should run into the same problem again, I'll report back :)

> >
> > Maybe it's a version-specific issue...
> 
> No, no changes since about two years, the problem was when escaping the
> output, which has nothing to do with this problem.

thanks for the clarification.

Erdmut


-- 
Erdmut Pfeifer
science+computing gmbh

-- Bugs come in through open windows. Keep Windows shut! --

Re: reading from files

Posted by Gerald Richter <ri...@ecos.de>.
> On Fri, Feb 16, 2001 at 10:05:22AM -0800, Wim Kerkhoff wrote:
> > I forgot about the optRawInput trick. I added
> >
> > [- $escmode=0; $optRawInput = 1 -]
> >

[- $optRawInput = 1 -]

Should work, setting $escmode to zero doesn't seems to be a good idea,
because it may cause problem if the content you read from the file/pipe does
contain any characters that had to escaped.

> > to uptime.html and base.html with no luck. Back ticking the < only give
> > me a "[19646]ERR: 24: Line 7: Error in Perl code: (in cleanup)
> > Unterminated <> operator...." error :P
>

You should set either $optRawInput = 1 or use the backslash before the <UP>.
The error message looks like, you have used both. This will not work.

BTW you could set EMBPERL_OPTIONS to 1 in your httpd.conf, if you write all
your code with an ascii editor, then you don't have to add it to all pages,
but you shouldn't do that in case you use some highlevel html editor.

> that's strange... I have several code fragments like the following
> that work just as intended (they didn't wihout the "\<", however):
>

Yes, this works with the backslash as longs as optRawInput isn't set

>
> Maybe it's a version-specific issue...

No, no changes since about two years, the problem was when escaping the
output, which has nothing to do with this problem.

BTW. If optRawInput isn't set, you could also write   &lt;UP&gt;  this will
also work (there is always more then one way to do it :-)

Gerald


-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------



Re: reading from files

Posted by Erdmut Pfeifer <e....@science-computing.de>.
On Fri, Feb 16, 2001 at 10:05:22AM -0800, Wim Kerkhoff wrote:
> I forgot about the optRawInput trick. I added 
> 
> [- $escmode=0; $optRawInput = 1 -]
> 
> to uptime.html and base.html with no luck. Back ticking the < only give
> me a "[19646]ERR: 24: Line 7: Error in Perl code: (in cleanup)
> Unterminated <> operator...." error :P

that's strange... I have several code fragments like the following
that work just as intended (they didn't wihout the "\<", however):


[- open BJOBS, "/usr/local/bin/sudo -u $username /usr/local/lsf/bin/bjobs |"; -]
[$ while ( $line = \<BJOBS> ) $]
...
[$ endwhile $]


Maybe it's a version-specific issue... I'm not running the most recent
version (1.3b2) and I remember dimly that there was some discussion on
the list about escaping and security aspects -- followed by a rewrite
of some basic escaping mechanism. Don't know whether that explain's the
difference in behaviour... Gerald probably knows better ;)

Erdmut


-- 
Erdmut Pfeifer
science+computing gmbh

-- Bugs come in through open windows. Keep Windows shut! --

Re: reading from files

Posted by Wim Kerkhoff <wi...@merilus.com>.
I forgot about the optRawInput trick. I added 

[- $escmode=0; $optRawInput = 1 -]

to uptime.html and base.html with no luck. Back ticking the < only give
me a "[19646]ERR: 24: Line 7: Error in Perl code: (in cleanup)
Unterminated <> operator...." error :P

Erdmut Pfeifer wrote:
> 
> I would try to quote the "<"s in the perl code sections (i.e. "\<UP>",
> etc.), at least that's what I usually do in these situations.
> There may be a way to achieve the same effect via configuration options
> (optRawInput,...(?)), I haven't yet figured out how to make that work
> as advertised in the docs, though... (may be someone else can shed some
> light on that :)

-- 
Regards,

Wim Kerkhoff, Software Engineer
Merilus, Inc.
wim@merilus.com

Re: reading from files

Posted by Erdmut Pfeifer <e....@science-computing.de>.
On Fri, Feb 16, 2001 at 08:39:26AM -0800, Wim Kerkhoff wrote:
> Good morning/afternoon,
> 
> I've been trying to get a simple read from a pipe to work, but its not
> doing what I'm intending. I'm using EmbperlObject ('cuz it rocks), but
> get the same thing in just regular Embperl mode. My base.html is
> extremely simple: just the look and a Execute('*') call.
> 
> So, Uptime 2 works below, but not Uptime 1 and Uptime 3.  What am I
> doing wrong? It's gotta be something simple...
> 
> 
> --------------------------------
> Uptime 1:
>  
> [- open (UP, "uptime |") -]
>  
> [$ while ($line = (<UP>)) $]
>   <b>[+ $line +]</b>
> [$ endwhile $]
>  
> [- close (UP) -]
> 
> <br><br>
> Uptime 2: [+ `uptime` +]
> 
> <br><br>
> Uptime 3:
> [-
>   open (F, "uptime |");
>   while (<F>) {
>     print OUT $_;
>   }
>   close (F);
> -]
> 

I would try to quote the "<"s in the perl code sections (i.e. "\<UP>",
etc.), at least that's what I usually do in these situations.
There may be a way to achieve the same effect via configuration options
(optRawInput,...(?)), I haven't yet figured out how to make that work
as advertised in the docs, though... (may be someone else can shed some
light on that :)

Erdmut


-- 
Erdmut Pfeifer
science+computing gmbh

-- Bugs come in through open windows. Keep Windows shut! --