0

I am facing some trouble in running a shell script in my Ubuntu 16.04 from a Qt GUI application. onClick() for the push button is given below, which i found from How to start a Shell Script with QProcess?

void MainWindow::on_pushButton_clicked()
{
QProcess process;
process.startDetached("/bin/sh", QStringList()<< "/home/rahul/ifak/generateCAM.sh");
}

But unfortunately, this is not working in my case. When i replaced "gedit" with "/bin/sh", the script is opening up in gedit. Is this an issue with the way i am using "/bin/sh"? OR am i missing something else? Please give your valuable suggestions. Thanks in advance.

#!/bin/bash
SESSION=OpenC2X
CURR_DIR=$(pwd)
OPENC2X=$CURR_DIR/..
BUILD_DIR=$OPENC2X/build/
GLOBAL_CONFIG=$OPENC2X/common/config/config.xml

LOCAL_CONFIG_RELATIVE=config/config.xml
LOGGING_CONF=config/logging.conf
STATISTICS_CONF=config/statistics.conf

tmux -2 new-session -d -s $SESSION


tmux set-option -g mouse

tmux new-window -t $SESSION:1 -n 'App'

tmux split-window -h
tmux select-pane -t 0

tmux send-keys "cd $BUILD_DIR/cam/src" C-m
tmux send-keys "./cam $GLOBAL_CONFIG $OPENC2X/cam/$LOCAL_CONFIG_RELATIVE $OPENC2X/cam/$LOGGING_CONF $OPENC2X/cam/$STATISTICS_CONF" C-m
tmux split-window -v

tmux send-keys "cd $BUILD_DIR/httpServer/src" C-m
tmux send-keys "./httpServer $GLOBAL_CONFIG $OPENC2X/httpServer/$LOCAL_CONFIG_RELATIVE $OPENC2X/httpServer/$LOGGING_CONF $OPENC2X/httpServer/$STATISTICS_CONF" C-m
tmux split-window -v

tmux send-keys "cd $BUILD_DIR/ldm/src" C-m
tmux send-keys "rm ../db/ldm-*.db" C-m
tmux send-keys "./ldm $GLOBAL_CONFIG $OPENC2X/ldm/$LOGGING_CONF $OPENC2X/ldm/$STATISTICS_CONF" C-m
tmux split-window -v

tmux kill-pane
tmux select-pane -t 3

tmux send-keys "cd $BUILD_DIR/denm/src" C-m
tmux send-keys "./denm $GLOBAL_CONFIG $OPENC2X/denm/$LOGGING_CONF $OPENC2X/denm/$STATISTICS_CONF" C-m
tmux split-window -v

tmux send-keys "cd $BUILD_DIR/dcc/src" C-m
tmux send-keys "sudo ./dcc $GLOBAL_CONFIG $OPENC2X/dcc/$LOCAL_CONFIG_RELATIVE $OPENC2X/dcc/$LOGGING_CONF $OPENC2X/dcc/$STATISTICS_CONF" C-m
tmux split-window -v

tmux send-keys "cd $BUILD_DIR/obd2/src" C-m
tmux send-keys "./obd2 $GLOBAL_CONFIG $OPENC2X/obd2/$LOCAL_CONFIG_RELATIVE $OPENC2X/obd2/$LOGGING_CONF $OPENC2X/obd2/$STATISTICS_CONF" C-m
tmux split-window -v

tmux send-keys "cd $BUILD_DIR/gps/src" C-m
tmux send-keys "./gpsService $GLOBAL_CONFIG $OPENC2X/gps/$LOCAL_CONFIG_RELATIVE $OPENC2X/gps/$LOGGING_CONF $OPENC2X/gps/$STATISTICS_CONF" C-m

tmux -2 attach-session -t $SESSION
Rahul Raj
  • 1
  • 1
  • I have tested the code that shows and it works, maybe the problem is in the .sh file, you could show that file. – eyllanesc Oct 22 '17 at 19:49
  • For debugging purposes, start it without detaching, then `waitForStarted`, then see if you get error information. – hyde Oct 22 '17 at 20:28
  • The program is probably caused by the script running from the executable address, so I recommend using an absolute path. – eyllanesc Oct 22 '17 at 22:30
  • Please see the .sh file i added above. I am using tmux. Is that what is causing the issue? – Rahul Raj Oct 22 '17 at 23:05
  • Why do you start your shell script using `/bin/sh` (the script itself says `/bin/bash`) instead of marking it executable and execute it directly? – msrd0 Oct 22 '17 at 23:11
  • But i want to open the tmux terminal as well, without letting it simply run in the background. Because, i must provide the sudo password in the terminal and it shows some activity log as well. Is it not possible to open the tmux terminal from button press? – Rahul Raj Oct 23 '17 at 13:06

0 Answers0