【问题标题】:Running shell command in QT c++ in ubuntu在 ubuntu 中在 QT c++ 中运行 shell 命令
【发布时间】:2013-03-14 16:45:32
【问题描述】:

我在 ubuntu 中使用 Qt 5.0.1(64 位)。 我在按钮按下功能下运行以下命令。

QString command = "sh /home/rahul/qtapp/ques_new/ques_new/inter4ql/test1.sh"; const char* command2;

command2 = command.toLocal8Bit().data();

系统(命令2);

test1.sh文件内容是

!/bin/bash

回声“你好” 回声“你好”>> out.txt


按下按钮调用此系统命令时,它在输出窗口中显示 hello,但不会创建新文件 out.txt。

为了调试,我在调用此函数之前手动创建了 out.txt。但是,再次调用此函数后,它会在输出窗口中显示 hello,但不会将 hello 放入 out.txt。

【问题讨论】:

    标签: qt shell


    【解决方案1】:

    你的代码错了。

    试试:

    #!/bin/bash
    echo "hello" >> out.txt
    

    在这里工作没有任何问题。

    另外,文件可能不是在您正在查看的目录中创建的。你检查过你的脚本目录和你的应用程序工作目录吗?将out.txt 替换为完整路径(例如/home/derp/out.txt)。

    【讨论】:

      猜你喜欢
      • 2017-02-20
      • 2011-08-02
      • 1970-01-01
      • 2017-03-17
      • 2015-08-03
      • 2014-06-26
      • 1970-01-01
      • 2014-04-30
      • 2015-10-05
      相关资源
      最近更新 更多