Home
Man
Search
Today's Posts
Register

Post questions about C, C++, Java, SQL, and other programming languages here.

How to call Linux command in C

Tags
linux, linux commands, programming

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 04-08-2007
Data How to call Linux command in C

Dear Friends,
How we can call the Linux commands like ls, cat, grep, clear and others Linux commands in C programs.
# 2  
Old 04-08-2007
system call
or popen command

am pretty sure many such threads have been posted in the forum

if you do search thats a definite 'HIT'

But still,

Code:
sprintf(cmd, "/bin/ls -l");
system(cmd);

# 3  
Old 04-09-2007
Linux command by C programm

Hi,
I think u can also call Linux commands using the exec family functions.
for that u need to read IPC programming in C.
# 4  
Old 08-15-2007
Hi, I'm calling the split command from inside C and i'm wondering why it is not working (the file is not being split). Also, when I try executing only the unix command in the shell, it's working just fine. Am I missing something here? Below is my code:
Quote:
char cmd[100];
sprintf(cmd, "split -l 50 -a 1 /absolutepath/sample.txt");
system(cmd);
Thanks in advance!
# 5  
Old 08-26-2007
what is the return status of the system function call ( that uses split command ) ?
# 6  
Old 08-26-2007
main()
{
system("split -l 50 -a 1 /absolutepath/sample.txt");
return 0;
}
# 7  
Old 09-14-2007
Quote:
Originally Posted by sriram003
main()
{
system("split -l 50 -a 1 /absolutepath/sample.txt");
return 0;
}
If you could provide the return-value of system, one could examine why the call is failing.

try:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(const int argc, const char* const* const argv) {
 int res;
 int err;
 res = system("split -l 50 -a 1 /absolutepath/sample.txt");
 fprintf(stdout,"execution returned %d.\n",res);
 if ((-1 != res) && (127 != res))
  fprintf(stdout,"now would be a good time to check out 'man split' to check what the resulting return-value (%d) means.\n",res);
 return res;
}

Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help: how to call fork() in shell script? New to linux Xiaoya Ubuntu 2 09-11-2012 02:54 AM
Help: how to call fork() in shell script? New to linux Xiaoya Shell Programming and Scripting 0 09-11-2012 01:52 AM
Call function from Find command twjolson Shell Programming and Scripting 6 04-19-2012 06:57 PM
can a linux kernel module call libc functions? vistastar Programming 9 11-23-2011 05:01 AM
Perl - Call a sub routine in a command ab52 Shell Programming and Scripting 1 09-27-2011 02:23 PM
how to call dot c file using system command goraya430 Programming 4 05-14-2010 02:10 PM
how to call dot c file using system command goraya430 Shell Programming and Scripting 1 05-14-2010 10:58 AM
How to call a command in a batch file? Hari_Ganesh Windows & DOS: Issues & Discussions 1 03-12-2010 02:12 AM
How to implement a system call in linux? sunnyhay Linux 5 12-07-2009 11:21 AM
Need help with running the tar command using system() call in C vsanjit Programming 5 11-10-2008 07:17 PM
ioctl() system call on Linux-i386 aigoia UNIX for Advanced & Expert Users 1 09-15-2008 10:32 PM
command << EOF(dont want to call other script) user_prady Shell Programming and Scripting 4 11-15-2007 04:19 AM
How to call a Linux command in C prog. krishna_sicsr Shell Programming and Scripting 1 04-08-2007 04:53 AM
how can call perl script as command? umen UNIX for Dummies Questions & Answers 1 10-14-2005 10:43 PM
Making Socket System Call From Linux Kernel Module? mian_m_hamayun Linux 0 04-06-2005 10:34 AM


All times are GMT -4. The time now is 11:40 AM.

Unix & Linux Forums Content Copyright 1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password