How to Control the default Unix Shell from Perl

M

Mohsin

Hi all,
I have a perl program which makes a user exit to the O/S (unix, solaris)
to issue a O/S command. I know that the shell it invokes is NOT a
korn shell, because I captured the shell info into a file with a
'ps' command. My question is "How to explicitly specify a Korn shell to
be used by perl?"

Eg of my perl code:

## Begin code snippet..

$cmd = "ps > msgfile ";

open( OUT, "| $cmd ");
close (OUT);

## End code snippet.


....After this piece of code there is a 'msgfile' created and its
contents are:

PID TTY TIME CMD
5528 pts/3 0:00 ksh
5584 pts/3 0:00 trial.pl
5585 pts/3 0:00 sh


The 1st line is my session (korn). The 3rd line is the shell (NOT KORN!)
that PERL invoked to run the process in the 2nd line (trial.pl)

Please help.

regards
Mq
 
J

Jim Gibson

Mohsin said:
Hi all,
I have a perl program which makes a user exit to the O/S (unix, solaris)
to issue a O/S command. I know that the shell it invokes is NOT a
korn shell, because I captured the shell info into a file with a
'ps' command. My question is "How to explicitly specify a Korn shell to
be used by perl?"

Eg of my perl code:

[snipped]

As far as I know, you can't specify the shell to use. Perl uses the
Bourne shell (sh). To use another shell, write a shell script that
calls the script you want to run under ksh. Then call this new script
from your Perl program. Pass arguments as needed.

FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future
for better response.
 
N

nobull

Subject: How to Control the default Unix Shell from Perl

IIRC you can only do this at build-time in Unix. (On Win32 there's a
registry entry).
My question is "How to explicitly specify a Korn shell to
be used by perl?"

That is a different question - you don't want to change the _default_,
just tell Perl to use something else. That you can do.
open( OUT, "| $cmd ");

my $chosen_shell = '/usr/bin/ksh'; # Or just 'ksh' or $ENV{SHELL}
open( OUT,'|-',$chosen_shell,'-c',$cmd)
or die "Can't spawn $chosen_shell: $!";

Note - the list syntax for pipe-opens is a recent feature.

Working out what unpleasant quoting you'd need on older Perls to get
/bin/sh to run you chosen shell, is left as an exercise for the
reader.

This newsgroup does not exist (see FAQ). Please do not start threads
here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top