Calling a different shell than the inherited one

Discussion in 'Perl Misc' started by dn_perl@hotmail.com, Nov 17, 2003.

  1. Guest

    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?
     
    , Nov 17, 2003
    #1
    1. Advertising

  2. <> wrote:
    > 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).

    --
    Glenn Jackman
    NCF Sysadmin
     
    Glenn Jackman, Nov 17, 2003
    #2
    1. Advertising

  3. Ben Morrow Guest

    () wrote:
    > 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

    --
    don't get my sympathy hanging out the 15th floor. you've changed the locks 3
    times, he still comes reeling though the door, and soon he'll get to you, teach
    you how to get to purest hell. you do it to yourself and that's what really
    hurts is you do it to yourself just you, you and noone else *
     
    Ben Morrow, Nov 17, 2003
    #3
  4. () writes:

    > 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\\
     
    Brian McCauley, Nov 17, 2003
    #4
  5. On 16 Nov 2003 18:55:51 -0800
    () wrote:

    > 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!
     
    James Willmore, Nov 17, 2003
    #5
  6. Anno Siegel Guest

    Mark <> wrote in comp.lang.perl.misc:
    > <> wrote in message
    > news:...
    >
    > > 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.


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

    Anno
     
    Anno Siegel, Nov 18, 2003
    #6
    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:
    5
    Views:
    563
    Thomas J. Gritzan
    Oct 6, 2006
  2. Merciadri Luca
    Replies:
    4
    Views:
    835
  3. 7stud --
    Replies:
    11
    Views:
    426
    7stud --
    Nov 9, 2007
  4. Steven D'Aprano
    Replies:
    0
    Views:
    116
    Steven D'Aprano
    Dec 23, 2013
  5. Replies:
    3
    Views:
    98
    Gary Herron
    Dec 23, 2013
Loading...

Share This Page