查看完整版本: [-- 请问一个关于Qt中调用sh脚本的问题。 --]

QTCN开发网 -> Qt基础编程 -> 请问一个关于Qt中调用sh脚本的问题。 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

czy1996 2017-04-16 20:04

请问一个关于Qt中调用sh脚本的问题。

是这样的,做了一个为文件加密的系统,想利用Qt做一个图形化界面。想先调用enc1.sh(带两个参数,用Qt的Line Edit传进来),再调用一个cpabe-dec的可执行文件(也带俩参数,用Qt 的Line Edit传进来),再调用一个enc2.sh。然后查阅了一下资料,程序写成了这样:
  1. void Encrypt::on_encBtn_clicked()
    {
        QString s1 = ui->fileLineEdit->text();
        QString s2 = ui->pswdLineEdit->text();
        QString s3 = ui->xLineEdit->text();
        QString command;
        QString command1;
        QString command2;
        command.append("./enc1.sh");
        command.append(" ");
        command.append(s1);
        command.append(" ");
        command.append(s2);
        command1.append("./enc2.sh");
        command1.append(" ");
        command1.append(s1);
        command1.append(" ");
        command1.append(s2);
        command2.append("./cpabe-enc pub_key ");
        command2.append(s2);
        command2.append(" ");
        command2.append(s3);
        QProcess p(0);
        p.setWorkingDirectory("/Users/czy/Desktop/cpabe");
        p.start(command);
        p.start(command2);
        p.start(command1);
        p.waitForFinished();
    }
然后这段代码跑不出结果...没有执行我sh文件里的操作..我知道肯定哪里出问题了。恳请指教!

其实我就是想在终端里面跑这几句:
./enc1.sh s1 s2
./cpabe-enc pub_key s2 s3
./enc2.sh s1 s2
其实这3个步骤是给文件加密的过程。


笑颜 2017-04-17 09:12
If the QProcess object is already running a process, a warning may be printed at the console, and the existing process will continue running unaffected.

p.start(command);
p.waitForFinished();
p.start(command2);
p.waitForFinished();
p.start(command1);
p.waitForFinished();

试试吧!


查看完整版本: [-- 请问一个关于Qt中调用sh脚本的问题。 --] [-- top --]



Powered by phpwind v8.7 Code ©2003-2011 phpwind
Gzip disabled