C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-12-2007, 06:34 AM   #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?
nickkrym is offline   Reply With Quote
Old 05-12-2007, 06:46 AM   #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.
__________________
MacGyver is offline   Reply With Quote
Old 05-12-2007, 06:47 AM   #3
Woof, woof!
 
zacs7's Avatar
 
Join Date: Mar 2007
Location: Australia
Posts: 3,295
What error checking have you done?
Do you have some sample code...?
__________________
"I.T. gets the chicky-babes" - M. Kelly
bakefile | vim
zacs7 is offline   Reply With Quote
Old 05-12-2007, 07:33 AM   #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'
nickkrym is offline   Reply With Quote
Old 05-12-2007, 08:01 AM   #5
and the hat of Jobseeking
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,699
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.

Salem is offline   Reply With Quote
Old 05-12-2007, 08:04 AM   #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
nickkrym is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 03:23 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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