How to Control the default Unix Shell from Perl

Discussion in 'Perl' started by Mohsin, Jan 20, 2004.

  1. Mohsin

    Mohsin Guest

    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
     
    Mohsin, Jan 20, 2004
    #1
    1. Advertising

  2. Mohsin

    Jim Gibson Guest

    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.
     
    Jim Gibson, Jan 22, 2004
    #2
    1. Advertising

  3. Mohsin

    Guest

    (Mohsin) wrote in message news:<>...
    > 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.
     
    , Jan 23, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    5,781
    Jonathan Bromley
    Feb 18, 2005
  2. dpackwood
    Replies:
    3
    Views:
    1,830
  3. Robert Wallace

    my own perl "dos->unix"/"unix->dos"

    Robert Wallace, Jan 21, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    295
    Michele Dondi
    Jan 22, 2004
  4. NewBie
    Replies:
    2
    Views:
    93
    Brian McCauley
    Jul 23, 2004
  5. Simon O
    Replies:
    8
    Views:
    179
    Mumia W.
    Jun 15, 2006
Loading...

Share This Page