1

I have a python program that is calling an external command. The command needs to look like this:

java -jar ../GeoNetCWBQuery-4.0.2-bin.jar -s "NZMQZ..HH..." -d 3600 -event:time
"2004/12/26 00:58:50" -event:lat "3.3" -event:lon "95.78" -event:depth "10.0"
-o %c%s%y%/M%/D%z

In the python program I have assigned names to the values which need to go into the command i.e. date, time, lat, lon, depth. (I can't just type in the values as I am looping over a huge file.) So my question is, how do I write it out i.e how do I insert the values into the command correctly. At the moment I have (which is not working):

os.system('java -jar GeoNetCWBQuery-4.0.2-bin.jar -s "NZMQZ..HH..." -d 3600
-event:time " + date + +time + " -event:lat " + lat + " -event:lon " + lon +
" -event:depth " + depth + " -o %c%s%y%M%D%z')
1

1 Answer 1

2

You have some trouble with single/double quotes.

os.system('java -jar GeoNetCWBQuery-4.0.2-bin.jar -s "NZMQZ..HH..." -d 3600
-event:time ' + date + time + ' -event:lat ' + lat + ' -event:lon ' + lon +
' -event:depth ' + depth + ' -o %c%s%y%M%D%z')

Also, as Udo Klein notes you should not use os.system anymore, prefer subprocess.call. If you are going to change os.system to subprocess.call you code will look like:

subprocess.call('java', ['-jar', 'GeoNetCWBQuery-4.0.2-bin.jar', '-s', 'NZMQZ..HH...', '-d', '3600',
'-event:time', date, time,  '-event:lat', lat, '-event:lon', lon, 
'-event:depth', depth, '-o', '%c%s%y%M%D%z'])
Sign up to request clarification or add additional context in comments.

1 Comment

@sasha.sochka: How can I call C:\Program Files (x86)\MSBuild\12.0\Bin\msbuild "D:\WebService\IDEWebService.sln" /p:DeployOnBuild=true /p:PublishProfile="D:\WebService\Properties\PublishProfiles\MyDeployment.pubxml" /p:AllowUntrustedCertificate=true /p:UserName=Admin /p:Password=password from python3.4 `

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.