execute command in CURRENT shell

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Valentine Kouznetsov

    execute command in CURRENT shell

    Hi,
    simple question, how to execute command in current shell, not in
    subshell?

    Example. I have environment variable A=aaa and need to invoke shell
    (sh) script which will do something with A. If I do os.system() then
    sub-shell will setup A
    and execute my script there leaving A in parent shell untouched.

    Thanks,
    Valentine.
  • Rob Williscroft

    #2
    Re: execute command in CURRENT shell

    Valentine Kouznetsov wrote in news:ec6d1a16.0 308080828.367f6 b54
    @posting.google .com:
    [color=blue]
    > Hi,
    > simple question, how to execute command in current shell, not in
    > subshell?
    >
    > Example. I have environment variable A=aaa and need to invoke shell
    > (sh) script which will do something with A. If I do os.system() then
    > sub-shell will setup A
    > and execute my script there leaving A in parent shell untouched.
    >[/color]

    A hack for you:

    Create a new sh script. say new.sh:

    #!/bin/sh
    source $*
    echo Result=$A
    # ----------------


    #!/bin/python
    import os

    command="origin al.sh arg1, arg2" # you get the idea

    #Sorry don't know how you need to invoke sh
    w = os.popen( "sh ./new.sh " + command )

    while ( True ):
    s = w.readline()
    if not s:
    break
    if s.startswith( "Result=" ):
    os.environ[ "A" ] = s[ s.find( "=" ) + 1 : ] )
    break
    # Or maybe read all lines - so you get the last "Result="!

    w.close()

    HTH

    Rob.
    --

    Comment

    Working...