Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google site



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

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 09-02-2001
Registered User
 

Join Date: Aug 2001
Posts: 10
Angry check my code?? running shell from c?

Hi mates,
i am trying to run a shell command from my C program in this case let is say the "ls" command. It copiles it okay, and even creates the new fork too. But seems to nothing is happening i mean it is not showing the result of the "ls" command.

I don't know wat i am doing wrong. Any comment will be appreciated.

abdul


#include <unistd.h>
#include <sys/wait.h>
#include <stdio.h>

int p_id;
int child_status;
int cpid;

main()
{
cpid=fork();

switch (cpid)
{
case -1:
perror("fork");
exit(1);
case 0:
printf("The fork is successful!\n");
system('ls');
exit(0);
default:
wait(&child_status);
}
}
Sponsored Links
  #2 (permalink)  
Old 09-03-2001
mib mib is offline
Registered User
 

Join Date: Jan 2001
Location: Calicut
Posts: 228
It worked for me with a slight change.

system("ls");


BTW: Please post C related questions in "C Programming in the UNIX Environment" section. Thanks.
Sponsored Links
Closed Thread

Bookmarks

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
how to check if a process is running in a server from shell script. debu UNIX for Advanced & Expert Users 2 01-24-2008 05:19 PM
Compile a code for running on boot d4n1l0d Filesystems, Disks and Memory 2 08-14-2006 03:44 PM
How can i check my code .. Dastard Shell Programming and Scripting 5 08-10-2006 02:26 AM
How to check for specific process running through shell agp Shell Programming and Scripting 3 03-25-2006 06:24 AM
Perl running C code gdboling Shell Programming and Scripting 1 09-02-2003 07:43 PM



All times are GMT -4. The time now is 03:47 AM.


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-2010. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0