2

Im using Python's subprocess module to run a dxl script. My Problem is when i try to catch the Output (In this example a print-statement or a error message) of my dxl script, it is shown in the command prompt, but when i try to catch it with stdout=subprocess.PIPE or subprocess.check_output it always returns an empty string. Is there a way to catch the output or how could I get the Error messages from Doors? It's important that you dont see the GUI of DOORS.

Here is my quick example that shows my problem:

test.dxl

print "Hello World"

test.py

import subprocess
doorsPath = "C:\\Program Files (x86)\\IBM\\Rational\\DOORS\\9.5\\bin\\doors.exe"
userInfo = ' -user dude -password 1234 -d 127.0.0.1 -batch ".\\test.dxl"'
dxl = " -W"

output = subprocess.check_output(doorsPath+dxl+userInfo)
print(output)

Edit: Using Windows 7 , DOORS 9.5 and Python 2.7

TooBroke
  • 103
  • 1
  • 8
  • what happens if you run the same command in Windows console but with redirection (append `> output.txt` at the end of the command)? Do you see the result in the file? Unrelated: use raw-string literals such as `r'C:\Program..'` for Windows paths (to avoid escaping the backslashes). – jfs Oct 07 '15 at 15:59
  • Thanks for the raw-string tipp and i will try it the windows console tomorrow when im back at work. – TooBroke Oct 07 '15 at 16:28
  • @J.F.Sebastian So i tried it and it creates a command prompt with the "Hello World" Message and a output.txt file which is empty :( – TooBroke Oct 08 '15 at 09:05
  • If `doors.exe` [prints directly to Windows console outside its stdout, stderr](http://stackoverflow.com/a/20981435) then see if there is a command-line switch that redirects the output to more accessible places (such as files) otherwise you might need to emulate Windows console (there is pseudo-tty on UNIX but it is completely different on Windows). – jfs Oct 08 '15 at 09:40
  • More worked around the problem with printing the data to a file and read it with python. But nontheless solved it, so a big thank you to @J.F.Sebastian :) – TooBroke Oct 09 '15 at 13:42

3 Answers3

0

I know this post is pretty old, but the solution to the problem is to use cout << ... instead of print. You can override the print perms like shown here DOORS Print Redirect Tutorial for print, cout and logfiles

Mathias Mamsch
  • 323
  • 1
  • 15
0

I'm feeling lucky here,

change print "Hello World" to cout << "Hello World"

and userInfo = ' -user dude -password 1234 -d 127.0.0.1 -batch ".\\test.dxl > D:\output.txt"', as in cmd promt the text can be directly exported to a text file.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Mayur Raj
  • 61
  • 5
-1

your script have many error try this link for example for subprocess

and try this :

import subprocess
import sys

path = "C:\\Program Files(x86)\\IBM\\Rational\\DOORS\\9.5\\bin\\doors.exe"
userInfo = "C:\\Program Files (x86)\\IBM\\Rational\\DOORS\\9.5\\bin\\doors.exe"

proc = subprocess.Popen([path,userInfo,"-W"])
proc.communicate()

i hape it work on your system!

Najeeb Choudhary
  • 396
  • 1
  • 3
  • 21
  • you are posting almost the same wrong answer to several `subprocess`-related questions. (1) don't use `sys.executable` unless you want to run a child Python script using the same python interpreter as your parent Python script (`doors.exe` doesn't look like it) (2) why do you think that `stdin=PIPE` (redirecting standard input) has anything to do with the issue in the question? OP wants to get output from the subprocess -- your code does not try to capture the output. (3) I don't understand why you put `path` into `userInfo` – jfs Oct 07 '15 at 16:08
  • @Najeeb Choudhary This answer isnt helpful at all. If there are so many errors in my script can you pls post a solution? – TooBroke Oct 07 '15 at 16:27
  • @TooBroke i went to know what is door.exe. which kind of program? – Najeeb Choudhary Oct 08 '15 at 06:32
  • [DOORS(Wikipedia)](https://en.wikipedia.org/wiki/DOORS) You can access the data of DOORS with the Doors eXtension Language (dxl) without starting the GUI. Thats what im doing. To easier show my problem in the dxl script is only `print "Hello World"` written. – TooBroke Oct 08 '15 at 07:57