1

I use "spim" emulator to emulate the mips architecture. The way it works is that I should first have a "filename.asm" file, I then type "spim" in bash to open the command line interpreter for spim, then I can use the spim commands like loading the file and running it, etc..

I am trying to write a python script that opens the spim command line interpreter and starts typing spim commands in it. Is this possible?

Thanks.

Tim
  • 41,901
  • 18
  • 127
  • 145
Keeto
  • 4,074
  • 9
  • 35
  • 58

2 Answers2

1

This is going to depend on spim, which I'm not familiar with, but if you can pipe something to it, you can do the same in Python

Check out http://docs.python.org/library/subprocess.html

Something like this will get you started:

proc = subprocess.Popen('spim',shell = True,stdin = subprocess.PIPE)
proc.stdin.write("Hello world")
dfb
  • 13,133
  • 2
  • 31
  • 52
0
from subprocess import Popen, PIPE, STDOUT

# Open Pipe to communicate with spim process.
p = Popen(['spim'], stdout=PIPE, stdin=PIPE, stderr=STDOUT, shell=True)

# Write a "step 1" command to spim.
p.stdin.write('step 1\n')
p.stdin.close()

# Get the spim process output.
spim_stdout = p.stdout.read()
print(spim_stdout)
  • 1
    You can make this more helpful to the OP and future SO'ers by taking the time to explain what you've done. – Jay Blanchard May 08 '14 at 18:00
  • This code don't solve the problem if you need iteratively communicate with spim process. Always create a new instantiation of process. When you send "step 1" command the spim execute the first line. A workaround is send "step 1", "step 2", "step 3" and consider the last line of stdout result. Somebody know the manner in python to keep one opened channel with another process? (I need that spim works like a "jit" executing command by command, but inside a python subprocess.) – Rogério Aparecido Gonçalves May 08 '14 at 20:12