2013-05-09 48 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