开发者

Create directory by mkdir

开发者 https://www.devze.com 2023-04-08 22:37 出处:网络
I want to create a folder named by the user name in 开发者_StackOverflow中文版/tmp/vnc/, I can create that folder in command line with perl -e \'mkdir(\"$ENV{USER}\")\', but for the following code can

I want to create a folder named by the user name in 开发者_StackOverflow中文版/tmp/vnc/, I can create that folder in command line with perl -e 'mkdir("$ENV{USER}")', but for the following code cannot work.

chdir ("/tmp/vnc") or die -1;
mkdir ("$ENV{USER}", 0777) or die -1;

If I use mkdir -p /tmp/vnc/$ENV{USER} in command line to make folder, nothing happens and no error reports.


It works for me. Maybe the /tmp/vnc directory does not exist, and the chdir fails. Or maybe the $USER environment variable is not defined, because you are running it from a init.d script, for example... Or maybe you do not have write permissions in the /tmp/vnc directory. Have you tried executing mkdir /tmp/vnc/$USER from the shell?

Impossible to know more without details.


  1. Please check special variable $! for text error message
  2. Please check that variable $ENV{USER} doesn't contain extra quotes. I had similar problem in Windows OS for Activer Perl. My problem was in extra quotes


Perhaps something is resetting your environment when you are running the script? Can you print the contents of $ENV{USER} and make sure it contains what you think it should?


if $ENV{USR} is an absolute path (with the leading slash), then the chdir is useless since you are not using a relative path

0

精彩评论

暂无评论...
验证码 换一张
取 消