Calling a different shell than the inherited one

D

dn_perl

I often use C-shell for reasons beyond my control.

I want to call 'sqlplus' from within a perl script while
using c-shell. But I want the sqlplus to run in k-shell
or bash-shell. How can I do this? This is just an academic doubt.

If I use :
system("sqlplus username/password << EOH");
sqlplus statement one
sqlplus statement two
EOH

.... then won't the sqlplus run within the inherited C shell?
Or is there no such thing as the called sqlplus (or any other
called command) running within some shell?
 
G

Glenn Jackman

I often use C-shell for reasons beyond my control. [...]
If I use :
system("sqlplus username/password << EOH"); [...]
... then won't the sqlplus run within the inherited C shell?

'perldoc -f system' says that it won't:
If there is only one scalar argument, the argument is checked for
shell metacharacters, and if there are any, the entire argument is
passed to the system's command shell for parsing (this is "/bin/sh
-c" on Unix platforms, but varies on other platforms).
 
B

Ben Morrow

I often use C-shell for reasons beyond my control.

I want to call 'sqlplus' from within a perl script while
using c-shell. But I want the sqlplus to run in k-shell
or bash-shell. How can I do this? This is just an academic doubt.

If I use :
system("sqlplus username/password << EOH");
sqlplus statement one
sqlplus statement two
EOH

This Won't Work. See perlopentut for what you actually want to do.
... then won't the sqlplus run within the inherited C shell?
Or is there no such thing as the called sqlplus (or any other
called command) running within some shell?

If Perl calls the shell (it will only if the command contains shell
metacharacters) then it always calls /bin/sh.

Ben
 
B

Brian McCauley

I often use C-shell for reasons beyond my control.

I want to call 'sqlplus' from within a perl script while
using c-shell.

Why do you think that you want to do this?
But I want the sqlplus to run in k-shell or bash-shell.

Why do you think that you want to do this?
How can I do this?

If you want system() to start a process via a specific shell:

system('/bin/bash', '-c', 'sqlplus')
This is just an academic doubt.
Oh.

If I use :
system("sqlplus username/password << EOH");

You are confused. What are you expecting that here-doc to do? Do you
think that it is a shell here doc or a Perl one? You are passing '<<
EOH' to be parsed by /bin/sh but you are then putting the here-doc in
the Perl script.
sqlplus statement one
sqlplus statement two
EOH

I suspect you are trying to pass stuff to the sqlplus process STDIN.
You don't do that with system(). You do that with open().
... then won't the sqlplus run within the inherited C shell?

What do you mean by the 'inherited C shell'?

Did you mean the inherited environment setting? $ENV{SHELL} = '/bin/csh'

No, perl's system() ignores $ENV{SHELL}

Did you consider the possibilty of looking up the system() function in
the Perl reference manual at all?
Or is there no such thing as the called sqlplus (or any other
called command) running within some shell?

In some sense there is - but I don't think that is the sense in which
you meant it.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
J

James Willmore

On 16 Nov 2003 18:55:51 -0800
I often use C-shell for reasons beyond my control.

So do I at work. However, on servers that have bash installed, I just
type 'bash' and I get to use a real shell :)
I want to call 'sqlplus' from within a perl script while
using c-shell. But I want the sqlplus to run in k-shell
or bash-shell. How can I do this? This is just an academic doubt.
Huh?

If I use :
system("sqlplus username/password << EOH");
sqlplus statement one
sqlplus statement two
EOH

As I posted before ....

--untested--
my $sql_cmd = <<EOH;
username/password
sqlplus statement one
sqlplus statement two
EOH

system("sqlplus $sql_cmd");
--untested--

Now, at the command line, type
perldoc -q "Why don't my <<HERE documents work"
... then won't the sqlplus run within the inherited C shell?
Or is there no such thing as the called sqlplus (or any other
called command) running within some shell?

And then, after you're done reading that, type at the command line
perldoc -q "environment"

and then
perldoc perlvar
and search for "%ENV"

You may want to check out the DBI module - so you can interact with
the database from Perl without having to use another shell :)

HTH

--
Jim

Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.

a fortune quote ...
Help! I'm trapped in a PDP 11/70!
 
A

Anno Siegel

Mark said:
I often use C-shell for reasons beyond my control.

I want to call 'sqlplus' from within a perl script while
using c-shell. But I want the sqlplus to run in k-shell
or bash-shell. How can I do this? This is just an academic doubt.

If I use :
system("sqlplus username/password << EOH");
sqlplus statement one
sqlplus statement two
EOH

... then won't the sqlplus run within the inherited C shell?
Or is there no such thing as the called sqlplus (or any other
called command) running within some shell?

Have you tried setting an environment variable before making the system
call? Like,

$ENV{'SHELL'} = '/bin/bash';

That might do it.[/QUOTE]

Do you have any reason to say so, or are you just guessing?

Anno
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top