LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-11-2007, 08:48 PM   #1
amishmonkey
LQ Newbie
 
Registered: Sep 2005
Posts: 17

Rep: Reputation: 0
C syntax for terminal


What is the syntax in C to run a command in the terminal? For example, if I wanted to open the terminal and run a program that puts the line "ifconfig eth1 up" to the terminal...what would the command look like??

I do not want a script, because I want to be able to input more data into the program once information has been fetched from the terminal...am I making sense? I hope so!
 
Old 09-11-2007, 09:08 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You do realise a script and a prog are basically the same thing?
Granted C src is compiled and bash scripts aren't (for example), but they both do the same thing.
Having said that, sounds like you want the system() fn (which btw is actually a lib fn, not a system fn).
 
Old 09-11-2007, 09:12 PM   #3
amishmonkey
LQ Newbie
 
Registered: Sep 2005
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post
You do realise a script and a prog are basically the same thing?
Granted C src is compiled and bash scripts aren't (for example), but they both do the same thing.
Having said that, sounds like you want the system() fn (which btw is actually a lib fn, not a system fn).
It is my understanding that a script cannot be modified while running, while with C, or anyother language, can run, present information, user input, then further processing.

Ok, after some quick googling for syntax I now know that the system function is exactly what I was looking for! Thank you much!!

Last edited by amishmonkey; 09-11-2007 at 09:22 PM. Reason: "Problem" solved!
 
Old 09-11-2007, 10:14 PM   #4
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
Good, I'm glad you found your solution.

To further build on what chrism01 was saying, there really is no difference between scripts and compiled "programs" aside from the obvious matter that scripts are interpreted (at a high-level) and languages like Linux assembly, C and C++ are compiled (interpreted at an extremely low-level).

Both can provide the same functionality, just scripts are a little more pragmatic in some situations due to the fact that they're easier to modify (no need to recompile for every small change) and depending on the use, there may not be that much of an execution speed advantage.
 
  


Reply



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
making a script that opens terminal and enter commands into that terminal Cinematography Linux - General 8 12-16-2008 10:34 AM
Switching back to the Mandrake 9.1 desktop from terminal rdesktop terminal session marc218 Linux - General 6 02-08-2007 02:45 PM
How to launch an app in terminal, & keep it running after I close terminal? kornerr Linux - General 7 06-24-2006 05:54 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
Alternative terminal to konsole & gnome-terminal Adony Linux - Software 3 10-08-2004 03:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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
Open Source Consulting | Domain Registration