Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Avoiding surprises using 'open'

by Fastolfe (Vicar)
on Feb 03, 2001 at 04:30 UTC ( [id://56158]=note: print w/replies, xml ) Need Help??


in reply to (bbfu)(solution)Re: Re: VMS: Pipe to process
in thread VMS: Pipe to process

It's generally a good idea to put a leading space before the actual name of the file/command, not before any control characters that determine how the filehandle should be opened. Consider:
# this is pseudo-code $filename = '>test' or '+test' open(HANDLE, ">$filename"); # >>test or >+test (ruh-roh!) # likewise $filename = 'ls|' or '>test; open(HANDLE, "$filename"); # ls| (pipe) or clobbers 'test' # generally safe (in that behavior is not unexpected): open(PIPE, " $command |") open(PIPE, "| $command\0"); # safe version of "|ls" open(FILE, "> $filename\0"); # ">file" open(FILE, " $filename\0"); # "file"
In the last case, the presence of a space doesn't affect what is open, but since the first character is a space, any leading "mode" characters in $filename will be ignored, much like what was happening with your code.

Also see sysopen and perlipc (e.g., using fork/exec), which (in my opinion) are significantly more readable/safer than using weird manglings of open. Note that issues of shell meta-characters and other security considerations are out of the scope of this message. Each of the "PIPE" examples above are still incredibly insecure if untrusted input is allowed to use any shell metacharacters in the string. See perlsec and use Taint-checking.

Replies are listed 'Best First'.
(bbfu)(leading spaces, fork in VMS)Re: Fastolfe: Re: VMS: Pipe to process
by bbfu (Curate) on Feb 03, 2001 at 04:49 UTC

    Okay, thanks for the info! I think I understand how it works now. =)

    As for, fork()... I tried it and it's not supported in VMS. I think I'm really going to want a bi-directional pipe at some point but without fork() I think I'm gonna be SOL. =(

    Again, thanks much for explaining it to me! I couldn't remember where I'd heard that to look it up and perlipc didn't have that info (that I saw).

    bbfu
    Seasons don't fear The Reaper.
    Nor do the wind, the sun, and the rain.
    We can be like they are.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://56158]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 14:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found