Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ execute()一个DOS命令_C++_Qt_Command_Qprocess - Fatal编程技术网

C++ execute()一个DOS命令

C++ execute()一个DOS命令,c++,qt,command,qprocess,C++,Qt,Command,Qprocess,我正在尝试使用QProcess调用DOS命令:subst: QProcess process; int returnCode=process.execute(QString("subst " + DLetter+" "+mountPath)); qDebug()<<"returnCode"<<returnCode; if (returnCode==0){ qDebug()<<"Mount "<<QStri

我正在尝试使用
QProcess
调用DOS命令:
subst

 QProcess process;
    int returnCode=process.execute(QString("subst " + DLetter+"  "+mountPath));
    qDebug()<<"returnCode"<<returnCode;
    if (returnCode==0){
        qDebug()<<"Mount "<<QString("subst " + DLetter+"  "+mountPath)
                <<"error"<<process.errorString()<<"id"<<process.pid();
        process.waitForFinished();
        ...
    }else
        qDebug()<<" mounting folder failed  "<<process.errorString();
QProcess过程;
int returnCode=process.execute(QString(“subst”+DLetter+“”+mountPath));

qDebug()如果试图调用DOS函数,请尝试使用

#include <process.h>
...
system( "dir c:\\temp > c:\\temp\\output.txt" );
#包括
...
系统(“目录c:\\temp>c:\\temp\\output.txt”);
但这已经过时了。试用

int nRet= (int)ShellExecute( 0,"open","calc.exe",0,0,SW_SHOWNORMAL);
if ( nRet <= 32 )
{
        DWORD dw= GetLastError(); 
        char szMsg[250];
        FormatMessage(
            FORMAT_MESSAGE_FROM_SYSTEM, 
            0, dw, 0,
            szMsg, sizeof(szMsg),
            NULL 
        );
        MessageBox( szMsg, "Error launching Calculator" );
}
intnret=(int)ShellExecute(0,“打开”,“calc.exe”,0,0,SW_SHOWNORMAL);

if(nRet来自于

您应该这样做:

int returnCode=process::execute(QString("subst " + DLetter+"  "+mountPath));
qDebug()<<"returnCode"<<returnCode;
if (returnCode==0){
    qDebug()<<"Mount "<<QString("subst " + DLetter+"  "+mountPath)
            <<"error"<<process.errorString()<<"id"<<process.pid();
}else
    qDebug()<<" mounting folder failed  ";
int returnCode=process::execute(QString(“subst”+DLetter+“”+mountPath));

qDebug()感谢您的回复。首先,我使用
system()
调用我的命令,但是cmd会弹出并消失,我不希望在没有此弹出窗口的情况下以静默方式获取它(如果有避免此情况的选项,请让我知道),所以我将其替换为
QProcess
,我将尝试
ShellExecute()
请参见。我认为您需要直接调用cmd。类似于:cmd/c subst X:c:\\Test@drescherjm我需要从我的应用程序执行我的命令:)将该命令放在进程中。执行而不是您拥有的。是的,它已经是我拥有的,
QString(“subst”+DLetter+“”+mountPath)
是命令。我不是这个意思。命令中的cmd/c在哪里?如果要查看出错时执行的输出,需要使用非静态启动。我可以调查一下。我在windows上做过这件事。不适用于subst,但用于处理和发送医学图像,这是我日常工作的一部分。。