Problem with system(), execl(), etc. functions

This is a discussion on Problem with system(), execl(), etc. functions within the C Programming forums, part of the General Programming Boards category; Hi, Im trying to create an alias on a Linux system, which is very simple done through the command line ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    15

    Problem with system(), execl(), etc. functions

    Hi,

    Im trying to create an alias on a Linux system, which is very simple done through the command line by "alias my_command=another_command" for example, and then to remove the alias you use "unalias my_command". The problem is when I use system(), or the whole range of exec functions none of them work (for both creating, and removing the alias). Any ideas?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    I wrote some code before. It didn't work either. Why?

    Get the idea? You're not giving enough information. I think I'm going to suggest that the phrase "doesn't work" get auto-replaced on these forums by something else, at least when used at the end of a sentence.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    What error checking have you done?
    Do you have some sample code...?

  4. #4
    Registered User
    Join Date
    Dec 2006
    Posts
    15
    Sorry for the lack of details. What it boils down to is that the system already has an alias defined and I need to remove it. The relevant part of my application (called "plz"):
    Code:
    system("unalias temp");
    Output:
    root@nick:/home/nick# alias
    alias ls='ls --color=auto'

    root@nick:/home/nick# alias temp=/some/link

    root@nick:/home/nick# alias
    alias ls='ls --color=auto'
    alias temp='/some/link'

    root@nick:/home/nick# ./plz
    sh: line 0: unalias: temp: not found

    root@nick:/home/nick# alias
    alias ls='ls --color=auto'
    alias temp='/some/link'

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,590
    system() and exec() functions are for running actual programs.

    Aliases in your shell are basically nothing more than inline macros which get expanded into doing something by the shell.

    I hope you don't surf the web as well as doing development work as root.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  6. #6
    Registered User
    Join Date
    Dec 2006
    Posts
    15
    Thanks for the reply.

    So is it possible to envoke these macros from within a C application? Something along the lines of 'echo "unalias temp" | /bin/bash'?

    I usually don't use root but I was doing some configuration a second before i posted that, but thanks for noticing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Directory and System Problem
    By swanley007 in forum C++ Programming
    Replies: 6
    Last Post: 07-27-2006, 12:32 PM
  2. problem w/ color functions && win98 :P
    By DarkMortar in forum C Programming
    Replies: 2
    Last Post: 06-07-2006, 04:45 PM
  3. GTK+ Gnome desktop system tray app problem
    By BobS0327 in forum Linux Programming
    Replies: 2
    Last Post: 04-01-2006, 08:54 PM
  4. problem with multimaps and virtual functions
    By schlamniel in forum C++ Programming
    Replies: 4
    Last Post: 08-11-2004, 08:39 AM
  5. Functions problem. *Need Help*
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 03-28-2002, 11:50 AM

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