The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
grep unix.com with google



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-08-2007
Registered User
 

Join Date: Mar 2007
Posts: 25
Unhappy 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 (permalink)  
Old 04-08-2007
Technorati Master
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 3,006
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 (permalink)  
Old 04-09-2007
Registered User
 

Join Date: Mar 2007
Posts: 16
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 (permalink)  
Old 08-15-2007
Registered User
 

Join Date: Aug 2007
Location: Manila, Philippines
Posts: 3
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 (permalink)  
Old 08-26-2007
Technorati Master
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 3,006
what is the return status of the system function call ( that uses split command ) ?
  #6 (permalink)  
Old 08-26-2007
Registered User
 

Join Date: Mar 2007
Posts: 33
main()
{
system("split -l 50 -a 1 /absolutepath/sample.txt");
return 0;
}
  #7 (permalink)  
Old 09-14-2007
Registered User
 

Join Date: Sep 2007
Posts: 1
Quote:
Originally Posted by sriram003 View Post
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;
}

Sponsored Links
Closed Thread

Bookmarks

Tags
linux, linux commands

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
command << EOF(dont want to call other script) user_prady Shell Programming and Scripting 4 11-15-2007 04:19 AM
how to differentiate system call from library call muru UNIX for Advanced & Expert Users 2 07-20-2007 12:20 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 01:44 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0