Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > system PROGRAM LIST syntax

Reply
Thread Tools

system PROGRAM LIST syntax

 
 
jonathan
Guest
Posts: n/a
 
      01-05-2004
hey all,

I wanted to use this syntax to rename a complicated - and long - shell
function involving piping, teeing to another command, etc.
Unfortunately,

system { 'ls -lR' } 'secretls';

doesn't work, since it uses 'ls -lR' as the command itself, not ls
with -lR as an argument. I could rewrite this as:

system { 'ls' } 'secretls', '-lR';

which works for the simple case, but how about:

system( "ls -lR > 1 2>&1" );


I can't think of any syntax in list form that could replace this - and
of course, I *do* need to replace it for the sake of hiding entries in
the process table.


Any clue on how to do this?

Thanks much,

jon
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      01-05-2004

(jonathan) wrote:
> hey all,
>
> I wanted to use this syntax to rename a complicated - and long - shell
> function involving piping, teeing to another command, etc.
> Unfortunately,
>
> system { 'ls -lR' } 'secretls';
>
> doesn't work, since it uses 'ls -lR' as the command itself, not ls
> with -lR as an argument.


Yes. That's the point.

> I could rewrite this as:
> system { 'ls' } 'secretls', '-lR';
>
> which works for the simple case, but how about:
>
> system( "ls -lR > 1 2>&1" );


my $pid;
unless($pid = fork) {
defined $pid or die "fork failed: $!";
open STDOUT, ">", "1" or die "open failed: $!";
open STDERR, ">&", STDOUT or die "dup2 failed: $!";
exec { "/bin/ls" } "secretls", "-lR" or die "exec failed: $!";
}
{
local $SIG{TERM} = sub { kill TERM => $pid };
local $SIG{INT} = sub { kill INT => $pid };
-1 != waitpid $pid, 0 or die "waitpid failed: $!";
}

(I think).

> I can't think of any syntax in list form that could replace this - and
> of course, I *do* need to replace it for the sake of hiding entries in
> the process table.


This is entirely pointless. It is generally trivial to find out which
file a process is executing anyway (I believe BSDish systems keep 'ls'
in the process table entry somewhere; linux has /proc/*/exe;
etc.). Either do whatever you need to do in Perl, without invoking
external commands at all, or arrange things so it doesn't matter if
people see what programs you're running.

Ben

--
"If a book is worth reading when you are six, *
it is worth reading when you are sixty." - C.S.Lewis
 
Reply With Quote
 
 
 
 
pkent
Guest
Posts: n/a
 
      01-06-2004
In article < >,
(jonathan) wrote:

> which works for the simple case, but how about:
>
> system( "ls -lR > 1 2>&1" );


The problem there is that that's not a command followed by its
arguments; its a command, an argument and then _shell metacharacters_.
So you need a shellto execute - and with the multi-arg forms of system()
you're specifically not getting a shell, which means that thome
metacharacters aren't doing much.

Now, off the top of my head, how about:

system { 'sh' } 'secretls', '-c', 'ls -lR > 1 2>&1';

Because there you're executing sh(1) and giving it a string to parse...
Hang on I've just tried that and ps -Afw says:

pkent 12207 12206 1 23:18 pts/5 00:00:00 secretls -c ls -lR > 1
2>&1

which of course shows the args.

Actually, one thing you can do is open the relevant filehandles in perl
and do an exec() - no need to involve the shell at all! No need to use
redirection symbols! I think that the spawned ls(1) process would show
up but then it's a process, so it _has_ to show up.

Alternatively you can implement ls -lR in perl and then you have no need
of a subprocess at all! Already done, in fact, to some extent at
http://www.perl.com/language/ppt/src/ls/index.html

So there you go - do it all within perl

P

--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Checker that's better than the normal syntax checker Jacob Grover Ruby 5 07-18-2008 05:07 AM
Syntax error? What syntax error? Assignment fo default values? Mark Richards Perl Misc 3 11-18-2007 05:01 PM
Syntax bug, in 1.8.5? return not (some expr) <-- syntax error vsreturn (not (some expr)) <-- fine Good Night Moon Ruby 9 07-25-2007 04:51 PM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Syntax highligth with textile: Syntax+RedCloth ? gabriele renzi Ruby 2 12-31-2005 02:44 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57