| | |
In perl script system("cd c:\mnt"); is not working.
![]() |
•
•
Join Date: Dec 2008
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
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
----------------------------------------------
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
•
•
Join Date: Dec 2008
Posts: 2
Reputation:
Solved Threads: 0
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...
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.
I said chdir function. Don't use the system function to do this, use the chdir function.
http://perldoc.perl.org/functions/chdir.html
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
----------------------------------------------
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
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.
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.
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
----------------------------------------------
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
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:
Should work fine.
Perl Syntax (Toggle Plain Text)
$dir="d:\\somedir\\somesubdir"; chdir($dir);
Should work fine.
![]() |
Other Threads in the Perl Forum
- Previous Thread: perl project command line arg?
- Next Thread: perl/Cookie... basic question
| Thread Tools | Search this Thread |






