In perl script system("cd c:\mnt"); is not working.

Reply

Join Date: Dec 2008
Posts: 2
Reputation: aparna balkwade is an unknown quantity at this point 
Solved Threads: 0
aparna balkwade aparna balkwade is offline Offline
Newbie Poster

In perl script system("cd c:\mnt"); is not working.

 
0
  #1
Dec 10th, 2008
i m using perl script to do something where i want to change my current directory to mnt in c: only.. bt using function

system("cd c:\mnt"); is nt working.

system("dir"); is working properly ,also some other command using systems function in perl script is working fine bt dnt know what problem it is having with cd.

I also tried to change the drive c: to z:
system("z:"); bt its nt working.
these commands are working properly on command prompt bt nt in perl script.

even i used `cd c:\mnt` ,tried all combination with the `` but its nt doing.

can someone please help me?????????
its very urgent..
Thanks in advance for ur reply and also giving ur valuable time..

Waiting for reply..specially i hv joined this forum for this query i m nt getting its answer..plz help me.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,331
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 248
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: In perl script system("cd c:\mnt"); is not working.

 
0
  #2
Dec 10th, 2008
Each system command gets it's own "shell" (if you want to call it such, it's not really a complete shell, but it is an executiuon environment). So, the cd is working, but it's happening within that subshell, which means the shell in which the perl script itself is running, remains unchanged. Use the chdir function.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 2
Reputation: aparna balkwade is an unknown quantity at this point 
Solved Threads: 0
aparna balkwade aparna balkwade is offline Offline
Newbie Poster

Re: In perl script system("cd c:\mnt"); is not working.

 
0
  #3
Dec 10th, 2008
Thanks a lot for ur reply..
I tried using chdir also bt no use.
what i tried is ,
system 'chdir /D c:\\mnt';
system("chdir c:\\mnt");
even simply
chdir (c:\mnt);
chdir('c:\mnt');
`chdir c:\\mnt`;
bt its not responding...
what can be the reason????
I really need this to use in my code...

my complete script is,
=comment
use Win32::OLE;
$b = Win32::OLE->new('imacros') or die "iMacros Browser could not be started by Win32:OLE\n";
$b->{Visible} = 1;
$b->iimInit();
my $macro = "mount_share";
$b->iimPlay($macro);
$b->iimExit();
system("net use \\\\192.168.30.62\\share1 u1 /USER:u1");
system("net use c:\mnt \\\\192.168.30.62\\share1");

=cut

#@args=("cd", "c:\\mnt");
#system(@args);
print "cd c:\\mnt";

#system 'chdir /D c:\\mnt';
`chdir c:\\mnt`;
part which i hv commented is working nicely....bt stucked to that chdir part only....
thanks to give ur valuable time...
Last edited by aparna balkwade; Dec 10th, 2008 at 7:08 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,331
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 248
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: In perl script system("cd c:\mnt"); is not working.

 
0
  #4
Dec 10th, 2008
I said chdir function. Don't use the system function to do this, use the chdir function.

http://perldoc.perl.org/functions/chdir.html
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: In perl script system("cd c:\mnt"); is not working.

 
0
  #5
Dec 10th, 2008
try this, note the single-quotes:

chdir('c:\mnt') or die "Can't chdir to c:\\mnt : $!";

see if die returns an error.

Its actually better to use forward slashes even with windows, which fully supports their use in directory paths.

chdir('c:/mnt') or die "Can't chdir to c:/mnt : $!";

That way you avoid using perls escape operator \ in the wrong context in your perl code, like you did here:

chdir("c:\mnt");

which interpolates as:

chdir(c:nt);

or if the sequence \m is a valid meta character sequence perl would expand that into whatever it is (if anything). Like \t is a tab inside a double-quoted string.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: In perl script system("cd c:\mnt"); is not working.

 
0
  #6
Dec 10th, 2008
If its a mapped drive it may fail. I'm Not sure how you get perl to recognize a mapped drive. Maybe masijade will know.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,331
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 248
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: In perl script system("cd c:\mnt"); is not working.

 
0
  #7
Dec 11th, 2008
Originally Posted by KevinADC View Post
Maybe masijade will know.
Nope. Only have very limited experience in Perl on Windows. And, truth to tell, almost no experience in Perl the last four years, so I'm a bit rusty, anyway. ;-)
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 57
Reputation: mitchems is an unknown quantity at this point 
Solved Threads: 2
mitchems's Avatar
mitchems mitchems is offline Offline
Junior Poster in Training

Re: In perl script system("cd c:\mnt"); is not working.

 
0
  #8
Feb 5th, 2009
I use perl on Windows daily. If it is a mapped drive it will not fail. the file system functions work perfectly (chdir, copy, mkdir, etc.) on Windows but you have to either use a front slash (as you suggest above) or a double backslash if you are using double quotes. So:

  1. $dir="d:\\somedir\\somesubdir";
  2. chdir($dir);

Should work fine.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC