• 2849阅读
  • 1回复

[提问]请问一个关于Qt中调用sh脚本的问题。 [复制链接]

上一主题 下一主题
离线czy1996
 

只看楼主 正序阅读 楼主  发表于: 2017-04-16
关键词: QProcessshell
是这样的,做了一个为文件加密的系统,想利用Qt做一个图形界面。想先调用enc1.sh(带两个参数,用Qt的Line Edit传进来),再调用一个cpabe-dec的可执行文件(也带俩参数,用Qt 的Line Edit传进来),再调用一个enc2.sh。然后查阅了一下资料,程序写成了这样:
  1. void Encrypt::on_encBtn_clicked()
  2. {
  3.     QString s1 = ui->fileLineEdit->text();
  4.     QString s2 = ui->pswdLineEdit->text();
  5.     QString s3 = ui->xLineEdit->text();
  6.     QString command;
  7.     QString command1;
  8.     QString command2;
  9.     command.append("./enc1.sh");
  10.     command.append(" ");
  11.     command.append(s1);
  12.     command.append(" ");
  13.     command.append(s2);
  14.     command1.append("./enc2.sh");
  15.     command1.append(" ");
  16.     command1.append(s1);
  17.     command1.append(" ");
  18.     command1.append(s2);
  19.     command2.append("./cpabe-enc pub_key ");
  20.     command2.append(s2);
  21.     command2.append(" ");
  22.     command2.append(s3);
  23.     QProcess p(0);
  24.     p.setWorkingDirectory("/Users/czy/Desktop/cpabe");
  25.     p.start(command);
  26.     p.start(command2);
  27.     p.start(command1);
  28.     p.waitForFinished();
  29. }
然后这段代码跑不出结果...没有执行我sh文件里的操作..我知道肯定哪里出问题了。恳请指教!

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

Haha,you are here again!
离线笑颜

只看该作者 1楼 发表于: 2017-04-17
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();

试试吧!
快速回复
限100 字节
 
上一个 下一个