start() terminal with command by QProcess

关键:

QString exec = "xterm"; //选择终端

QStringList params; //****** 这是关键:在输入终端中,输入的参数流 ******

params << "-hold" << "-e" << "ls" << "-l"; // 不同的终端,一般参数也不相同。

@saber

You still don't state what it is you want to happen in the terminal, I'm tearing my hair out! Does it sit there interactively doing nothing waiting for the user to type some commands, or does it run some command (which you won't tell us about), show its output, leave the window there awaitng you to only close it, and that's it?

Using xterm I'll show you both of these:

  1. Sits interactively:

    QProcess *process =new QProcess();
    QString exec= "xterm";
    process->start(exec);
  1. Runs ls -l, output in the xterm, does not accept any further commands, leaves window open, user can close window:

    QProcess *process = new QProcess();
    QString exec = "xterm";  //选择终端
    QStringList params; //****** 这是关键:在输入终端中,输入的参数流 ******
    params << "-hold" << "-e" << "ls" << "-l";  // 不同的终端,一般参数也不相同。
    process->start(exec, params);

When one of these does whatever you want we might be getting somewhere....?

@JonB i want the second one .

just open the terminal with the commnad and sit there .

here is the code for htop

QString l(QDir::homePath());
    QProcess *process = new QProcess();
        QString exec = "xterm";
        QStringList params;
        params << "-hold" << "-e" << "htop" ;
        process->setWorkingDirectory(l);
        process->start(exec, params);

start terminal with command by QProcess

https://forum.qt.io/topic/93735/start-terminal-with-command-by-qprocess/17

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值