LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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


Hi
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, 08:52 AM   #2
linuxlover.chaitanya
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, 09:01 AM   #3
pixellany
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, 09:11 AM   #4
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 297

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

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
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, 06:12 PM   #6
soleilarw
Member
 
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 05:17 AM.
 
  


Reply


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 08:54 AM
How to make GUI for shell script ? Joydeep Bakshi Linux - Software 3 11-07-2007 02:43 AM
command with shell script sunlinux Programming 2 12-29-2006 12:36 AM
Command in shell script Grassie Coetzee Linux - Software 1 03-13-2005 12:42 PM
How to make a simple addition in a shell script. philipina Programming 2 03-16-2004 05:38 AM


All times are GMT -5. The time now is 08:24 PM.

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