Perl system access denied
I'm running the following on a windows machine as an administrator
system("tracert 192.168.63.1 > d:\netmon\test.txt");
the output is Access Denied. Running the tracert without creating the file works fine. So Why can't I create the file in the existing netmon directory. I have full access to that directory.
Can somebody point me in the right directio开发者_开发百科n. Thanks
In Perl, the backslash (\) is a special character inside of double quotes, used to "escape" other special characters or to specify other untypeable characters. The sequences "\n" and "\t", which are contained in your example, are used to produce the newline and the tab character, respectively.
To produce a literal backslash character inside of double quotes, we use two consecutive backslash characters, so:
system("tracert 192.168.63.1 > d:\\netmon\\test.txt");
will produce the results you want.
Perl treats strings enclosed by single quotes ('') differently from double quotes. Inside single quotes, \ is not a special character (well actually, it is still a little bit special, but a lot less special than inside double quotes), so you could also have written your expression as:
system('tracert 192.168.63.1 > d:\netmon\test.txt');
If you use \ in your path, you need to double up:
system("tracert 192.168.63.1 > d:\\netmon\\test.txt");
Or you could just use a slash instead:
system('tracert 192.168.63.1 > d:/netmon/test.txt');
加载中,请稍侯......
精彩评论