Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > How to Control the default Unix Shell from Perl

Reply
Thread Tools

How to Control the default Unix Shell from Perl

 
 
Mohsin
Guest
Posts: n/a
 
      01-20-2004
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
 
Reply With Quote
 
 
 
 
Jim Gibson
Guest
Posts: n/a
 
      01-22-2004
In article < >, Mohsin
<> 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.
 
Reply With Quote
 
 
 
 
nobull@mail.com
Guest
Posts: n/a
 
      01-23-2004
(Mohsin) wrote in message news:<. 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.
 
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
Unix shell script with Perl one-liner causes error Simon O Perl Misc 8 06-15-2006 04:06 PM
Required Perl Developer w/ UNIX. SQL and Shell Scripting. iLogicnet Solutions Team Perl Misc 5 03-27-2006 01:53 AM
can I run unix shell command in the ModelSim shell? clinton__bill@hotmail.com VHDL 2 02-18-2005 10:04 PM
Unix shell interactive with perl - NewBie NewBie Perl Misc 2 07-23-2004 07:50 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 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