By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,706 Members | 2,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,706 IT Pros & Developers. It's quick & easy.

How to Control the default Unix Shell from Perl

P: n/a
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
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <cf**************************@posting.google.com >, Mohsin
<mo******@hotmail.com> wrote:
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.
Jul 19 '05 #2

P: n/a
mo******@hotmail.com (Mohsin) wrote in message news:<cf**************************@posting.google. com>...
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.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.