Click to See Complete Forum and Search --> : perl use of system() command


glitch003
12-03-2002, 07:17 PM
ok heres my question: i wanna make a program in perl(BTW im just learning perl) that just sends commands to the console. but heres the problem: say i type "ls". it gives me the contents of the root folder(my home folder). so then i type "cd .." and hit enter. then i type "ls". it still gives me the contents of the root folder. if i type "cd ..; ls" then it will display the contents of the / folder, like i want. all i want to use this program for is for making shortcuts, with if statements(ex. "droot" to set my current dir to root). please help and tell me why it does this. code is below:





#!/usr/bin/perl
print "CCOS1.00: ";
while ($input = <STDIN>){
system ("$input");
print "CCOS1.00: ";
}

raz0rblade
12-04-2002, 08:56 AM
I don't have a solution, but i know why it's doing that. system(); calls one command thourgh sh and prints it. what your code is really doing is passing a command to sh, then ends sh and starts over again. it's not storing the commands your using. hope this was helpful.

glitch003
12-04-2002, 06:25 PM
oh ok. do u kno of any way to make it now end the sh?