Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 05-26-2009, 07:50 AM   #1
LQ Newbie
Registered: May 2009
Posts: 1

Rep: Reputation: 0
How to make system(command) to runinside a shell script?

I am building my applications's UI in Qt 4.4.3. I need to invoke some external shell script on click of a button click . Also i need to invoke "system-config-network" command from the shell script. Earlier i thought of using system("system-config-network") inside shell script but it didnt work out. Please suggest.
Old 05-26-2009, 07:52 AM   #2
Senior Member
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
If you are talking about bash shell script then you do not need any function as such. If you just write the command it will be executed by shell.
Old 05-26-2009, 08:01 AM   #3
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
If you are using Qt, that implies that you are writing in C. Most languages have something like a "system" call to let you use shell commands. I don't recall how C does this.
Old 05-26-2009, 08:11 AM   #4
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 299

Rep: Reputation: 62
What exactly is going wrong when you invoke system("system-config-network")?
Old 05-26-2009, 08:19 AM   #5
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,074

Rep: Reputation: 386Reputation: 386Reputation: 386Reputation: 386
It's not clear at all to me what you try to do.

However, bear in mind that the C++ domain has nothing to do with the bash domain, and that you MUST abide the correct syntax for each one when you are using it.

The fact that you are calling bash from within a QT program is irrelevant, the bash script needs to abide the bash syntax. And in bash you never do something like "system()", because simply bash doesn't work that way. Bash is a command interpreter by itself, it doesn't need to do a system() call to launch a program, and it can't call a qt or c++ function either.

I assume that "system-config-network" is a command line tool. Isn't it? What does the script do that you can't code in C++ directly? Calling an additional shell instance might be an overkill.
Old 05-26-2009, 05:12 PM   #6
Registered: Apr 2009
Posts: 107

Rep: Reputation: 19
In C/C++ 'system' is part of stdlib.h:

#include <stdlib.h>
int system(const char *command);

If you know the location and name of the launchable tool, then the code line is like:

system ("ls -l /bin/* > bintools.file");

Linux Archive

Last edited by soleilarw; 06-18-2009 at 04:17 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
A command on shell which does not make system calls piyush masrani Linux - General 12 07-26-2008 07:54 AM
How to make GUI for shell script ? Joydeep Bakshi Linux - Software 3 11-07-2007 01:43 AM
command with shell script sunlinux Programming 2 12-28-2006 11:36 PM
Command in shell script Grassie Coetzee Linux - Software 1 03-13-2005 11:42 AM
How to make a simple addition in a shell script. philipina Programming 2 03-16-2004 04:38 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:21 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration