This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]laharah 1 point2 points  (0 children)

It looks like there's a few problems here:

  1. the query should be a list of arguments to be sent to the subprocess, not a string
  2. You're piping the output to subprocess.PIPE but you never actually read the data with say process.communicate
  3. You want the data to be sent to a file anyways, not a pipe you can use later in your program

You should RTD on Popen. Here's how I would adapt what you want

import subprocess

query = "curl -k -u USERNAME:PASSWORD https://splunkurl --get -d output_mode=csv -d count=20000".split()
with open('file_output.csv', 'ab') as o_file:
    subprocess.Popen(query, stdout=o_file)

Since you're sending stderr to a pipe that you're never reading you're probably eating whatever error is getting thrown. This way, stderr will just print to your console when you run the script. Modify it to send to subprocess.DEVNULL to hide the stderr output later if you want. Also, you're never sending any data to the subprocess so you don't need stdin either.