472,133 Members | 1,177 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

How to Control the default Unix Shell from Perl

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
2 5543
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
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.

Similar topics

22 posts views Thread by Ryan M | last post: by
1 post views Thread by Thierry Missimilly | last post: by
2 posts views Thread by Paddy | last post: by
4 posts views Thread by Ignoramus6539 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.