473,461 Members | 1,672 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 5649
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Ryan M | last post by:
I've been programming for a while, but most of my experience is on unix. How do C compilers work on operating systems that weren't written in C? And that have no libc? Compiling C on unix seems...
1
by: Thierry Missimilly | last post by:
Hi Postgres users, I wonder to know if it is possible to launch a Perl program or a unix comand in a trigger function. I have tried to do that in a C trigger developed with the SPI function....
2
by: tfoxusenet | last post by:
Hi, I need to encrypt/decrypt some data for my C# application that can also be read on a unix system, and need a quick, simple, cross-platform solution I can embed in my own code that doesn't...
2
by: Paddy | last post by:
Hi, Anyone know of something that can turn an interactive bash or tcsh session into a test the way doctest does? - Cheers, Paddy.
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
4
by: nidhikhandelwal | last post by:
I am calling a unix shell script from a perl script by using the following system command: system("./readfile_new.sh"); but it seems the unix script readfile_new.sh is not being called. Can...
2
by: sunilsn | last post by:
Hi, I am newbie to perl, I hope you guys will help me resolve the challenge I am facing. I have a unix shell script on one UNIX machine say A, and a batch file on windows machine say B. Now I want...
2
by: pisupati | last post by:
Hi, I need to a solution through perlscript. I have a unix process (ksh) running in a unix box. In the middle (of this process) there is a need to call a windows program and execute some steps...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.