On Tue, 2004-04-20 at 13:55, Larry Wall wrote:
> Okay, let's put this one to rest.
Good, and I'll not try to speak ill of the dead thread, so ignoring hash
and/or array access, let me respond to the end of your message.
> As for C<qx//>, it probably needs to be completely rethought anyway,
> along with C<system>. Perhaps both will be subsumed under a C<run>
> function of some sort. But that's for a future Apocalypse.
Now, you had to go and do it didn'cha? ;-)
I've been thinking about this for a long time, but for other reasons.
It seems to me that there are dozens of ways to run a program from
within Perl 5. Some are simple, some ugly as sin (sorry, I mean
"complex"), but given A12, I think we can start to home in on a great
deal of the standard tools.
In specific, here is a proposal for execution:
multi run(string $command) returns(Process) {...} # Funky shell default
multi run(Process $process) returns(Process) {...} # Relies on $process.cmdline
multi run(Program $program, IO::Mode $mode=undef) returns(Process) {...}
which gives us our process control, all nicely bottled up:
my Process $p = run("find / -name null");
say "Spawned find $($p.getpid)";
$p.kill('TERM');
But if you don't want that, you can always:
run("find / -name null").wait;
which might have an alias called "system".
And if you provide mode:
my Process $p = run(program=>"find / -name null", mode=>"r");
Then you actually get back a:
class ExecPipe is Process does IO::Handle {...}
which lets you do:
say "Found null at: $p.getline";
and which could have a wrapper:
$x = readpipe("pwd");
ahhh... simple.
open2, open3, exec and all manner of other strange things should be
simple aliases for complex run invocations.
The reason for making Program an object? Why for this:
run(Program(path=>"find",name=>"finding null",args=>[<</ -name
null>>],exec=>true));
which has the alias "exec".
Making this as magical as Perl 5 system would be difficult, though, and
I'm not sure you need to preserve that particular way of doing things.
I leave the definition of Program up to the imagination of the reader.
Incidentally, if Process is a standard class, and happens to do:
class Process {
...
method prefix:~() { return ~($.getpid) }
method prefix:+() { return $.getpid }
...
}
Then $$ is just a Process object, but behaves exactly as you always
expected it to.
$$.kill("ABRT")
then does what you might expect, as does:
say $$.cmdline;
--
Aaron Sherman <[EMAIL PROTECTED]>
Senior Systems Engineer and Toolsmith
"It's the sound of a satellite saying, 'get me down!'" -Shriekback