0

I am using python 2.5 in windows xp. In this i am using subprocess to run my shell, now how should i has to run gdb in shell using subprocess.

my code:

PID = subprocess.Popen('C:/STM/STxP70_Toolset_2010.2/bin/STxP70.bat', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE).

Now shell will open, next if i try to run gdb using communicate by

PID.communicate ("gdb"),

"gdb" is not running in the shell.

What should i has to do for this.

Sagar Gupta M.
  • 359
  • 1
  • 3
  • 5
  • http://stackoverflow.com/questions/3482869/invoke-and-control-gdb-from-python seems like it might be what you're after. It's hard to tell what you are asking though. – Matthew Iselin Jan 27 '11 at 05:32
  • sorry i have made changes in my question. – Sagar Gupta M. Jan 27 '11 at 05:43
  • Why are you trying to run gdb in a subprocess? Can you explain? It feels like you are trying to solve a problem the wrong way. – Lennart Regebro Jan 27 '11 at 11:17
  • The requirement is that from a python script i has to run a module through gdb and later i also has to run my model, then later i has to compare the outputs of these. Even i dont know the exact reason for this, but thats what i got the requirment from my project lead. – Sagar Gupta M. Jan 27 '11 at 13:05

1 Answers1

1

Your code:

  1. Starts STxP70.bat
  2. Writes string "gdb" (with no terminating newline) to it's standard input and closes the standard input.
  3. Is reading it's output until end of file. PID.communicate won't let you to interact with the subprocess any further—it writes the provided string and than collects all output until the process terminates.
  4. When STxP70.bat completes, the subprocess terminates.

Note, that if "shell will open" means a new window comes up with a shell prompt in it, you are screwed. It would mean the STxP70.bat stared it with 'start' command and you can't communicate with that, because it's not inheriting your stdin/stdout/stderr pipes. You would have to create your own modification of the batch that will not use 'start'.

.

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172
  • Actually i want to run the gdb in shell, that i am trying to do with 'communicate' after making the subprocess. So how can i do that. Do even for this i has to change my .bat file. Or is there any other way cos .bat file can't be changed. – Sagar Gupta M. Jan 27 '11 at 08:16