0

Environment - PyCharm

I am using the below command to get the JSON file:-

aws rds describe-db-cluster-snapshots > snapshotdetails.json

I am using this Json file to extract some data. I want the above command to run from my Python script. I have tried below but its failing:-

from subprocess import call
call(["aws rds describe-db-cluster-snapshots > snapshotdetails.json"])

I am getting error and its not working. Any pointers??

Error:-

Traceback (most recent call last):File "/Users/PrashastKumar/Desktop/CrossRegion/venv/lib/crossregiontrial.py", line 3, in <module>
call(["aws rds describe-db-cluster-snapshots > snapshotdetails.txt"])
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
  • Not without seeing the error. – DopeGhoti May 8 '18 at 21:57
  • @JohnMiliter: you mean to say i need to use below – Prashast May 8 '18 at 22:01
  • call(["aws", "rds", "describe-db-cluster-snapshots" > snapshotdetails.txt"]) – Prashast May 8 '18 at 22:02
  • call(["aws", "rds", "describe-db-cluster-snapshots", ">snapshotdetails.txt"]) -- used this , but getting error "Unknown options: >snapshotdetails.txt" – Prashast May 8 '18 at 22:03
  • 1
0

A python3 solution:

from subprocess import Popen, PIPE
cmd_output = Popen(["echo", "foo"], stdout=PIPE)
with open('bar.txt', 'w') as out_handle:
    out_handle.write(cmd_output.communicate()[0].decode('UTF-8'))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.