2013-05-09 127 views
3

我正在寻找一种使用matlab与uci协议进行通信的国际象棋引擎的方法。 国际象棋引擎是rybka和它的exe文件。当我运行rybka.exe时,我可以通过dos命令提示符进行通信,但是我想通过matlab来完成。 我想我必须使用streampipe和stdin和stdout,但我不知道如何使用它。如何与使用matlab的uci协议进行通信

我发现在Python这个代码,它工作正常,但我在寻找一个matlab版本:

import subprocess, time 

engine = subprocess.Popen(
    'a.exe', 
    universal_newlines=True, 
    stdin=subprocess.PIPE, 
    stdout=subprocess.PIPE, 
) 

def put(command): 
    print('\nyou:\n\t'+command) 
    engine.stdin.write(command+'\n') 

def get(): 
    # using the 'isready' command (engine has to answer 'readyok') 
    # to indicate current last line of stdout 
    engine.stdin.write('isready\n') 
    print('\nengine:') 
    while True: 
     text = engine.stdout.readline().strip() 
     if text == 'readyok': 
      break 
     if text !='': 
      print('\t'+text) 

回答

0

如果它只是使用的exe文件,并捕获它的输出,你可以使用system的情况下,命令来捕获输出。例如,我可以通过以下方式运行系统的dir命令:

>> [~, output] = system('dir') 

output = 

ant  ant.cmd antRun.bat antenv.cmd   envset.cmd runant.pl 
ant.bat antRun antRun.pl complete-ant-cmd.pl lcp.bat  runant.py 

文档:http://www.mathworks.com/help/matlab/ref/system.html

参见:Running C program's executable from Matlab and getting the output