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

N

n00m

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

and some.exe get only 'line1'...
 
N

n00m

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
 
A

alexelder

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.
 
P

Peter Otten

n00m said:
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
 
N

n00m

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()
 
N

n00m

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?
 

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,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top