How to pass a multiline arg to exec('some.exe arg')?

Discussion in 'Python' started by n00m, May 5, 2008.

  1. n00m

    n00m Guest

    os:windows
    ml = 'line1 \n line2 \n line3 \n'
    exec('some.exe "' + ml + '"')

    and some.exe get only 'line1'...
     
    n00m, May 5, 2008
    #1
    1. Advertising

  2. n00m

    n00m Guest

    Hint:
    for some reason in VBScript it works fine.
    What makes it different, with Python?
    I tried all possible ways to combine quotes, ' and ",
    with no avail
     
    n00m, May 5, 2008
    #2
    1. Advertising

  3. n00m

    Guest

    On May 5, 10:25 am, n00m <> wrote:
    > os:windows
    > ml = 'line1 \n line2 \n line3 \n'
    > exec('some.exe "' + ml + '"')
    >
    > and some.exe get only 'line1'...


    I think your problem lies with your "\n", escape chars. Assuming these
    are not arguments and are indeed separating statements, I suggest
    replacing "\n", with "&". That way, the command shell probably wont
    complain.

    An example:
    ml = 'line1 & line2 & line3'

    Alex.
     
    , May 5, 2008
    #3
  4. n00m

    Peter Otten Guest

    n00m wrote:

    > os:windows
    > ml = 'line1 \n line2 \n line3 \n'
    > exec('some.exe "' + ml + '"')
    >
    > and some.exe get only 'line1'...


    My crystall ball says you want

    subprocess.call(["some.exe", ml])

    exec is a python statement that executes python code.

    Peter
     
    Peter Otten, May 5, 2008
    #4
  5. n00m

    n00m Guest

    actually, it's this doesn't work (again, in VBS the "same"
    construction works properly):

    f = os.popen('osql -E -S(local) -dpubs -w800 -Q"' + query + '"', 'r')

    res=f.readlines()

    =======
    here "query" is a multiline string like:

    select getdate()

    select 555*666

    select getdate()
     
    n00m, May 5, 2008
    #5
  6. n00m

    n00m Guest

    it can be done like this:

    osql=popen2.popen2('osql -E -S(local) -dpubs -c"GO" -n -
    w800')
    osql[1].write(query+'\nGO\n')
    osql[1].close()
    res=osql[0].readlines()
    osql[0].close()
    res=join(res,'')

    btw, is it necessarily to close() osql[1] in order to get res?
    without close() the script seems is waiting for smth.
    I'd like to get "res" in a loop:
    write()
    read()
    write()
    read()
    ....
    is it possible?
     
    n00m, May 5, 2008
    #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. Hal Vaughan
    Replies:
    11
    Views:
    1,179
    Gordon Beaton
    May 22, 2006
  2. Alan G Isaac

    Python 3: exec arg 1

    Alan G Isaac, Jan 17, 2009, in forum: Python
    Replies:
    8
    Views:
    923
    Alan G Isaac
    Jan 22, 2009
  3. dale zhang
    Replies:
    8
    Views:
    452
    Tintin
    Nov 30, 2004
  4. Replies:
    7
    Views:
    196
  5. Replies:
    21
    Views:
    406
    Barry Schwarz
    Mar 5, 2014
Loading...

Share This Page