0

I know there's a way to access output using subprocess.check_output:

output = subprocess.check_output(["python", "nxptest.py", "my_testlist.txt"])

but what is I need to go to nxptest.py first and access the function present in that module. eg.

python commands_for_nxptest.py

which opens up interactive consol and then

get_test_no()

where get_test_no() is function defined in commands_for_nxptest.py module. How should I do that using subprocess.check_output??

I tried :

output = subprocess.check_output("python commands_for_nxptest.py")
time.sleep(0.5)
output1 = subprocess.check_output("get_test_no()")
print output1

This doesn't work though..

tryPy
  • 71
  • 1
  • 11

1 Answers1

2

Generally, you don't use subprocess to call other Python files. You just import them and call whatever you need directly.

import commands_for_nxptest
output1 = commands_for_nxptest.get_test_no()
Kevin
  • 74,910
  • 12
  • 133
  • 166
  • I'm developing a GUI for my testcases so I can't import it the way you suggested. I need to print the output1 to textblock in my gui. That's why I mentioned about using subprocess.check_output in my question. – tryPy Oct 23 '14 at 19:11
  • @tryPy: [edit](http://stackoverflow.com/posts/26534956/edit) your question and include reasons why you can't import the module (GUI is not the reason, code that creates GUI imports modules all the time), why you need to capture stdout (instead of using the returned value from the function), why you can't capture if you indeed need it (here's [how to redirect temporarily stdout to a file/(file like object)](http://stackoverflow.com/a/22434262/4279)). – jfs Oct 24 '14 at 14:34