System calls in c

This is a discussion on System calls in c within the Linux Programming forums, part of the Platform Specific Boards category; Hi Everyone. I'm having problems with system calls, basically the commands that i can put into my terminal are fine ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Location
    Glasvegas, Scotland.
    Posts
    68

    System calls in c

    Hi Everyone. I'm having problems with system calls, basically the commands that i can put into my terminal are fine but don't work as system calls from c.
    I'm using tcsh.
    In other words:
    Code:
    (23) dino-shill:>setenv W_DIR widthdirectory
    (24) dino-shill:>echo $W_DIR
    widthdirectory
    and in C:

    Code:
    	if(width < 20)
    	{
    	printf("cd 2amp/eps/10mto20m\n");
    	system("setenv W_DIR 2amp/eps/10mto20m");
    	system("echo $W_DIR");
    	}
    output:
    Code:
    cd 2amp/eps/3m6to10m
    sh: setenv: command not found
    Is it because the c program is using sh while i am using tcsh?
    How do i tell the program to use tcsh?

    Thanks

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Try using the setenv() and getenv() functions for environment variables.

    Todd
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    You seem confused about what system() does. It invokes a shell, runs the command, then returns. That means that anything you do in that system() call will not "stick." You can't change directories, and you certainly can't set environment variables.

    Like Todd Burch said, you have to call setenv() and getenv() directly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic system calls help.
    By AmbliKai in forum C Programming
    Replies: 5
    Last Post: 03-21-2008, 08:18 AM
  2. Opinions on custom system build
    By lightatdawn in forum Tech Board
    Replies: 2
    Last Post: 10-18-2005, 05:15 AM
  3. Problem With My Box
    By HaVoX in forum Tech Board
    Replies: 9
    Last Post: 10-15-2005, 08:38 AM
  4. School Mini-Project on C/C++ (Need Your Help)..
    By EazTerence in forum C++ Programming
    Replies: 4
    Last Post: 09-08-2005, 02:08 AM
  5. System Calls && Variables
    By Okiesmokie in forum C++ Programming
    Replies: 6
    Last Post: 03-06-2002, 09:10 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21