943,522 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 5806
  • Perl RSS
Dec 10th, 2008
0

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

Expand Post »
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
aparna balkwade is offline Offline
2 posts
since Dec 2008
Dec 10th, 2008
0

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

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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Dec 10th, 2008
0

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

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
aparna balkwade is offline Offline
2 posts
since Dec 2008
Dec 10th, 2008
0

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

I said chdir function. Don't use the system function to do this, use the chdir function.

http://perldoc.perl.org/functions/chdir.html
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Dec 10th, 2008
0

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

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.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Dec 10th, 2008
0

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

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.
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Dec 11th, 2008
0

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

Click to Expand / Collapse  Quote originally posted by KevinADC ...
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. ;-)
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Feb 5th, 2009
0

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

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:

Perl Syntax (Toggle Plain Text)
  1. $dir="d:\\somedir\\somesubdir";
  2. chdir($dir);

Should work fine.
Reputation Points: 26
Solved Threads: 38
Posting Whiz in Training
mitchems is offline Offline
293 posts
since Feb 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: perl project command line arg?
Next Thread in Perl Forum Timeline: perl/Cookie... basic question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC