Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: using pipes in a system() call

by swkronenfeld (Hermit)
on Dec 07, 2005 at 18:42 UTC ( #514972=note: print w/replies, xml ) Need Help??

in reply to using pipes in a system() call

Why don't you add a line before your system call...

print "find $home[$i]$dir -user $UID -print | xargs -n 1 chown -h $NEW +UID\n"; system("find $home[$i]$dir -user $UID -print | xargs -n 1 chown -h $NE +WUID");
Now you can see what it's expanding into with the variable interpolation. I'm guessing the variables aren't expanding into what you think they are.

Edit: Fletch's response to this node points out the dangerous situation that my suggestion can lead to. I'm leaving it in place as it's a valuable lesson to be learned.

Replies are listed 'Best First'.
Re^2: using pipes in a system() call
by Fletch (Bishop) on Dec 07, 2005 at 19:26 UTC

    Great idea, then he'll have two copies of the same string which can very easily get out of sync with each other leading to even more fun to track down bugs when it starts printing one thing and executing another!

    (This is why several people have recommended building the command in a scalar and print the scalar before passing it to system; change it once change it everywhere).

      Valid point Fletch.

      I wrote it the way I did because I was thinking of a short-term debugging effort, where the OP would erase the line after seeing what it expanded to. When passing shorter length system calls (and this applies to other functions as well), I prefer to have the command written inside the call, rather than forcing my brain to stop reading along with the flow of the program and backtrack to the $command variable definition.

      Regardless, not knowing how the OP would be using our advice though, I should not have posted like this.

        Yeah, not that I'm saying I haven't done just that myself before (and still do if it's really an emergency; then I get bitten and go back and wind up doing it the right way when I'm tracking down the bugs that caused . . . :).

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2022-12-10 04:48 GMT
Find Nodes?
    Voting Booth?

    No recent polls found