Shell Scripte via QT aufrufen
Verfasst: 5. Juli 2006 10:49
Hallo!
Ich verfolge im Moment eine sicherlich nicht sehr schöne Art und Weise, ein QT-Projekt zu erstellen.
Ich habe folgendes vor:
Ich habe bisher ein Fenster programmiert (Main Window) und mit verschiedenen Buttons belegt. Diese Buttons solllen ein C-Programm aufrufen.
Diese C-Programme sind natürlich nicht in die QT-Programmierung implementiert. Diese C-Programme werden stattdessen über Scripte extern aufgerufen. Genau an dieser Stelle liegt das Problem. Der Aufruf der Programm sieht so aus, dass die Konsole kurz aufflackert und sofort wieder geschlossen wird. Die C - Programme, sofern bei diesen keine weitere Eingabe notwendig ist, werden problemlos ausgeführt, dagegen werden C-Programme, die weitere Eingaben verlangen, nicht ausgeführt.
Woran kann das liegen?
Sicherlich werden sich viele User fragen, warum ich auf diesen Weg die QT Programmierung nutze, nun ich habe zuvor ein Programm geschrieben und erst jetzt hat sich ergeben, dass ich diesem Programm noch eine grafische Oberfläche geben möchte, daher nun diese Umsetzung.
Hier nun noch de Quelltext mit einem Beispielscript.
***************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
void MainForm::fileNew()
{
//not yet associated with a function
}
void MainForm::fileOpen()
{
//not yet associated with a function
}
void MainForm::fileSave()
{
//not yet associated with a function
}
void MainForm::fileSaveAs()
{
//not yet associated with a function
}
void MainForm::fileExit()
{
//not yet associated with a function
}
void MainForm::editCut()
{
//not yet associated with a function
}
void MainForm::editCopy()
{
//not yet associated with a function
}
void MainForm::editPaste()
{
//not yet associated with a function
}
void MainForm::editFind()
{
//not yet associated with a function
}
void MainForm::helpIndex()
{
//not yet associated with a function
}
void MainForm::helpContents()
{
//not yet associated with a function
}
void MainForm::helpAbout()
{
//not yet associated with a function
}
void MainForm::newSysConfig()
{
system("xterm -e .startzugriff.sh");
}
void MainForm::newIpScan()
{
system("xterm -e .startipscan.sh");
}
void MainForm::newIplist()
{
system("xterm -e .showiplist.sh");
}
void MainForm::newKeyClient()
{
//Systemaufruf von Schlüsselinstall!
}
void MainForm::newPing()
{
system("xterm");
system("xterm -e .testscript.sh");
}
void MainForm::newBing()
{
system("xterm");
}
void MainForm::newNetio()
{
//Systemaufruf von NETIO
}
void MainForm::newIperf()
{
//Systemaufruf von IPERF
}
void MainForm::newIperfClient()
{
//Systemaufruf von Iperf-Client
}
void MainForm::newNetioClient()
{
//Systemaufruf von Netio-Client
}
void MainForm::newFileTransfer()
{
//Systemaufruf von Filetransfer
}
###############################################
testscript.sh
#!/bin/sh
./testfile
sleep 3h
###############################################
testfile.c
#include<stdio.h>
int main()
{
printf("Testausgabe");
}
Anmerkung:
Rufe ich die Scripte über die Bash auf, so werden die Scripte auch in dieser ausgeführt. Rufe ich die Scripte unter xterm auf, so kommt es zu Fehlern. Mein Ziel wäre es, dass sich die Kommandozeile erst öffnet und nicht vorher geöffnet sein muss.
Ich verfolge im Moment eine sicherlich nicht sehr schöne Art und Weise, ein QT-Projekt zu erstellen.
Ich habe folgendes vor:
Ich habe bisher ein Fenster programmiert (Main Window) und mit verschiedenen Buttons belegt. Diese Buttons solllen ein C-Programm aufrufen.
Diese C-Programme sind natürlich nicht in die QT-Programmierung implementiert. Diese C-Programme werden stattdessen über Scripte extern aufgerufen. Genau an dieser Stelle liegt das Problem. Der Aufruf der Programm sieht so aus, dass die Konsole kurz aufflackert und sofort wieder geschlossen wird. Die C - Programme, sofern bei diesen keine weitere Eingabe notwendig ist, werden problemlos ausgeführt, dagegen werden C-Programme, die weitere Eingaben verlangen, nicht ausgeführt.
Woran kann das liegen?
Sicherlich werden sich viele User fragen, warum ich auf diesen Weg die QT Programmierung nutze, nun ich habe zuvor ein Programm geschrieben und erst jetzt hat sich ergeben, dass ich diesem Programm noch eine grafische Oberfläche geben möchte, daher nun diese Umsetzung.
Hier nun noch de Quelltext mit einem Beispielscript.
***************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
void MainForm::fileNew()
{
//not yet associated with a function
}
void MainForm::fileOpen()
{
//not yet associated with a function
}
void MainForm::fileSave()
{
//not yet associated with a function
}
void MainForm::fileSaveAs()
{
//not yet associated with a function
}
void MainForm::fileExit()
{
//not yet associated with a function
}
void MainForm::editCut()
{
//not yet associated with a function
}
void MainForm::editCopy()
{
//not yet associated with a function
}
void MainForm::editPaste()
{
//not yet associated with a function
}
void MainForm::editFind()
{
//not yet associated with a function
}
void MainForm::helpIndex()
{
//not yet associated with a function
}
void MainForm::helpContents()
{
//not yet associated with a function
}
void MainForm::helpAbout()
{
//not yet associated with a function
}
void MainForm::newSysConfig()
{
system("xterm -e .startzugriff.sh");
}
void MainForm::newIpScan()
{
system("xterm -e .startipscan.sh");
}
void MainForm::newIplist()
{
system("xterm -e .showiplist.sh");
}
void MainForm::newKeyClient()
{
//Systemaufruf von Schlüsselinstall!
}
void MainForm::newPing()
{
system("xterm");
system("xterm -e .testscript.sh");
}
void MainForm::newBing()
{
system("xterm");
}
void MainForm::newNetio()
{
//Systemaufruf von NETIO
}
void MainForm::newIperf()
{
//Systemaufruf von IPERF
}
void MainForm::newIperfClient()
{
//Systemaufruf von Iperf-Client
}
void MainForm::newNetioClient()
{
//Systemaufruf von Netio-Client
}
void MainForm::newFileTransfer()
{
//Systemaufruf von Filetransfer
}
###############################################
testscript.sh
#!/bin/sh
./testfile
sleep 3h
###############################################
testfile.c
#include<stdio.h>
int main()
{
printf("Testausgabe");
}
Anmerkung:
Rufe ich die Scripte über die Bash auf, so werden die Scripte auch in dieser ausgeführt. Rufe ich die Scripte unter xterm auf, so kommt es zu Fehlern. Mein Ziel wäre es, dass sich die Kommandozeile erst öffnet und nicht vorher geöffnet sein muss.