我面臨的問題我到目前爲止面臨了幾次。 有問題的問題每次都得到解決,沒有我瞭解是什麼導致它 所以會發生什麼是我從我的c + +代碼啓動一個python虛擬環境。這有效,之後通過使用寫入功能,我可以在該環境中寫入東西。這到目前爲止還是非常好的。但是我無法將最後一條命令寫入流程。 我雖然關於也許有些緩衝區已滿,但我真的沒有發現有關在Qt的文檔Qt - 如何將更多的數據寫入QProcess?
這是相關的代碼的緩衝區什麼:
static QStringList params;
QProcess *p = new QProcess();
params<<"-f"<<"-c"<<"python2"<< "/home/John/Desktop/python.log";
qDebug()<<"parameters: "<<params;
qDebug()<<"going to write";
p->start("script", params);
qDebug()<<"Turning on new user process...";
while(!p->waitForStarted())
{qDebug()<<"waiting for virtualenv to be ready";}
successFailWrite = p->write("import imp;\n");
while(!p->waitForBytesWritten());
successFailWrite = p->write("foo = imp.load_source('myTest', '/home/John/recognitionClass.py');\n");
while(!p->waitForBytesWritten());
successFailWrite = p->write("from myTest import recognitionClass;\n");
while(!p->waitForBytesWritten());
successFailWrite = p->write("myClassObj = recognitionClass();\n");
if(successFailWrite !=-1)
{qDebug()<<"OK written";}
while(!p->waitForBytesWritten());
successFailWrite = p->write("habelahabela\n");
if(successFailWrite !=-1)
{qDebug()<<"OK written";}
QString name = "John";
QString processNewUserParameter= "print myClassObj.addNewUser("+ name +");\n";
QByteArray processNewUserParameterByteArr= processNewUserParameter.toUtf8();
p->write(processNewUserParameterByteArr);
我把它包含一個日誌文件什麼被寫入到蟒蛇的virtualenv,什麼是被打印
Script started on Son 27 Aug 2017 20:09:52 CEST
import imp;
foo = imp.load_source('myTest', '/home/John/recognitionClass.py');
from myTest import recognitionClass;
myClassObj = recognitionClass();
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import imp;
>>> foo = imp.load_source('myTest', '/home/John/recognit
<myTest', '/home/John/recogniti onClass.py');
/usr/local/lib/python2.7/dist-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)
/usr/local/lib/python2.7/dist-packages/sklearn/grid_search.py:43: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. This module will be removed in 0.20.
DeprecationWarning)
>>> from myTest import recognitionClass;
>>> myClassObj = recognitionClass();
>>>
它pront「OK寫」兩次,這在一個側面證明,我成功地寫我的命令的過程中,但我看不到任何東西。
正如你所看到的,測試句子「habelahabela」不會被寫入。 有沒有人知道我可能做錯了什麼? 我知道我正在編寫我的命令以便快速進入環境。因爲正如你所看到的,我首先編寫「import imp」,然後緩衝,稍後緩衝區被刷新,virtualenv執行命令(這就是爲什麼你會看到它兩次)。
有人明白我爲什麼看不到測試句,更重要的是我的實際命令"print myClassObj.addNewUser("+ name +");\n"
被打印到虛擬環境中嗎?
感謝
該緩衝區是[pipe(7)](http://man7.org/linux/man-pages/man7/pipe.7.html)。您可能需要處理[readyRead](http://doc.qt.io/qt-5/qiodevice.html#readyRead)&[readyReadStandardOutput](http://doc.qt.io/qt-5/qprocess) 。html#readyReadStandardOutput)Qt信號 –
@BasileStarynkevitch確定thx澄清,你對我的問題有何建議? – LandonZeKepitelOfGreytBritn
花幾個小時閱讀文檔。另請閱讀關於[操作系統]的教科書(http://pages.cs.wisc.edu/~remzi/OSTEP/) –