0

I tried doing this in python and found questions here and here that look relevant, but I couldn't get it working from those answers. I am looking for a way to automate a manual process where I first change the directory and folder from the command prompt as follows.

d:

then

cd vph

then from the command prompt I run the following:

krr filename.xdf -vph 1,129 -s "StartFrequency: " -StartFrequency -n

The last line causes a frequency to be displayed at the command prompt. How can I save to a text file the frequency the last line returns, and how can I automate all the steps above? These steps need to be automated so I can do the same for over a thousand files. I worry nobody reading this has the krr software I need to use. If necessary, you can substitute the last line for something that will run on any windows computer and return a number. The "double-quotes" in the last line might be tricky if the last line needs to be in "double quotes".

Ted Ersek
  • 193
  • 2
  • 5

1 Answers1

0
import subprocess
#list of commands to be executed can be given one after another and add && between the commands. 
#Only when the first command execution is successful the next command will get executed
lst_cmd = "d && cd  vph && krr filename.xdf -vph 1,129 -s 'StartFrequency: ' -StartFrequency -n" 
out,err = subprocess.Popen(lst_cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE).communicate()
print ("the output is {}".format(out))
Prasanna P
  • 64
  • 1
  • 6
  • I was not able to check on the commands shared but validated the code with a different set of code and it worked fine. – Prasanna P Feb 10 '22 at 18:00