I want to try to use a command line script with my python application. The task is the following, my database stores some initial data for the script and
I need to execute a command line application in a following way:
$ application -parameter1 -file1
Here file1 is a file which contains my initial data, and parameter1 is an unrelated parameter.
The workflow as I see it now is the following:
initial_data = get_initial_data_from_db()
file = open('temp.txt', 'w+')
file.write(initial_data)
file.save()
os.popen4("application -parameter1 -file temp.txt")
I wonder if it’s possible to execute this script (called application) without writing the file with initial data to the hard disk? E.g. is there a way send the files contents to the command directly?
You can use the subprocess modul
something like that:
! if your application can read from stdin
Testing with Python as Application (in Eclipse) / after remark from Oleg Tarasenko :
Output: