![]() |
|
There's more than one way to do things | |
PerlMonks |
Re^5: forking and monitoring processesby revdiablo (Prior) |
on Jan 08, 2005 at 21:23 UTC ( [id://420594]=note: print w/replies, xml ) | Need Help?? |
There are a few problems here. The first is that by iterating on <@proc>, you're using glob to iterate on an array. It works in this case, but should not be used for that purpose. Instead, you should simply use:
The next, more critical problem, is in this code:
As the open docs state, this form of open does not pass the command through the shell, but rather executes it directly. The shell is where word splitting (e.g. "dir C:" to "dir", "C:") normally happens, but that won't happen here. That means you are attempting to execute a program called "dir C:". As you can imagine, you probably do not have that program on your system. Most of the time, the solution is to do something like this:
But in this case, you probably don't have a program named "dir" either. I might be wrong, but I think dir is built in to Win32's shell, cmd.exe. So you have two options. Either you can continue to use the same form of open, and call the shell yourself, or use the form of open that executes commands through the shell anyway. In this case, I would probably opt for the latter, for simplicity:
The last problem in your code is my fault. It's a bug I fixed, but apparently you grabbed the code before I did so. This line:
Should be changed to:
PS: If reading files in certain directories is your end goal, you might be able to accomplish it more easily with Perl builtins, such as readdir or glob, instead of shelling out to dir. But hopefully you will have learned something in the process. :-)
In Section
Seekers of Perl Wisdom
|
|