The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to get source code of Unix commands? jagdish.machhi@ Linux 4 08-10-2007 10:44 AM
need help with some commands please mujtba UNIX for Dummies Questions & Answers 2 01-14-2005 02:49 PM
commands kironpmullamkuz Security 2 06-27-2002 11:45 PM
commands Special K UNIX for Dummies Questions & Answers 3 02-13-2002 02:27 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-21-2007
Phrozen Smoke Phrozen Smoke is offline
Registered User
  
 

Join Date: Jan 2007
Location: India
Posts: 3
code that reads commands from the standard i/p and executes the commands

Hello all,
i've written a small piece of code that will read commands from standard input and executes the commands.
Its working fine and is execting the commands well. Accepting arguments too. e.g
#mkdir <name of the directory>

The problem is that its not letting me change the directory i.e pwd is remaining the same.
what changes should be made in it to let it change the directories too.

Code:
#include <stdio.h>
#include <string.h>
#define MAXLINE 50

int main(void)
{
        char buf[MAXLINE];

        printf("%% ");
        while (fgets(buf, MAXLINE, stdin) != NULL)
        {
                buf[strlen(buf) -1] = 0;
                system(buf);
                printf("%% ");
        }
}
regards
  #2 (permalink)  
Old 01-21-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
I don't think you have fully understood what your own code is doing, with respect to the context in which it is executing commands relative to the shell in which it is invoked.
  #3 (permalink)  
Old 01-21-2007
Phrozen Smoke Phrozen Smoke is offline
Registered User
  
 

Join Date: Jan 2007
Location: India
Posts: 3
Quote:
Originally Posted by reborg
I don't think you have fully understood what your own code is doing, with respect to the context in which it is executing commands relative to the shell in which it is invoked.
sorry to say that i'm still not clear...
  #4 (permalink)  
Old 01-21-2007
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
I'm saying this in simplistic terms but here is what happens in terms of processes:

Code:
   your shell
       +
       |
       +------Your application
                         +
                         |
                         +-------The command your program runs
If you make a change in the bootom node in this list it has no effect on the ones above it. You cannot chdir in the parent from a within a child.
  #5 (permalink)  
Old 01-22-2007
Phrozen Smoke Phrozen Smoke is offline
Registered User
  
 

Join Date: Jan 2007
Location: India
Posts: 3
okay...

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 On




All times are GMT -4. The time now is 06:53 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-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0