j*c 发帖数: 97 | 1 I don't know if this is a properiate board to post this question, but here it
is:
In perl, one can always read the system environment variable from pre-defined
hash %ENV. If one runs a perl script from a shell, it will inherit all the
environment variables available in the shell, including the system variables
like ARCH, USER, HOSTNAME etc. However, my problem is that if I submit a
job(in perl) to a job manager(Condor as we use), I can't get these variables
in %ENV. I suspect that Condor use a s |
D**e 发帖数: 10169 | 2 you sould be able to specify the shell in the job script in most of the batch
managers.
it
pre-defined
different
【在 j*c 的大作中提到】 : I don't know if this is a properiate board to post this question, but here it : is: : In perl, one can always read the system environment variable from pre-defined : hash %ENV. If one runs a perl script from a shell, it will inherit all the : environment variables available in the shell, including the system variables : like ARCH, USER, HOSTNAME etc. However, my problem is that if I submit a : job(in perl) to a job manager(Condor as we use), I can't get these variables : in %ENV. I suspect that Condor use a s
|
c*****e 发帖数: 32 | 3 不知你需要什么特定的环境变量,
可不可以写一个 shell 的 wrapper,这样可以先 invoke 你想要的 shell,
然后在wrapper 中调用你的 perl script?
it
pre-defined
different
【在 j*c 的大作中提到】 : I don't know if this is a properiate board to post this question, but here it : is: : In perl, one can always read the system environment variable from pre-defined : hash %ENV. If one runs a perl script from a shell, it will inherit all the : environment variables available in the shell, including the system variables : like ARCH, USER, HOSTNAME etc. However, my problem is that if I submit a : job(in perl) to a job manager(Condor as we use), I can't get these variables : in %ENV. I suspect that Condor use a s
|
j*c 发帖数: 97 | 4 The reason that I was writting a perl script is because I don't want to write
any shell script(actually I know very little about shell script). The specified
variables I want to know is "ARCH" or "OSTYPE" which always gives the type
of operation system (I need to invoke different binary and different parameter
files in my wrapper); and "USER", "HOSTNAME".
Thanks anyway, I will try to findout how to specify a shell in Condor.
【在 c*****e 的大作中提到】 : 不知你需要什么特定的环境变量, : 可不可以写一个 shell 的 wrapper,这样可以先 invoke 你想要的 shell, : 然后在wrapper 中调用你的 perl script? : : it : pre-defined : different
|
o***z 发帖数: 133 | 5 这些东东用uname -a之类的命令不能得到吗
user可以用whoami或者$<($UID)
【在 j*c 的大作中提到】 : The reason that I was writting a perl script is because I don't want to write : any shell script(actually I know very little about shell script). The specified : variables I want to know is "ARCH" or "OSTYPE" which always gives the type : of operation system (I need to invoke different binary and different parameter : files in my wrapper); and "USER", "HOSTNAME". : Thanks anyway, I will try to findout how to specify a shell in Condor.
|
j*c 发帖数: 97 | 6 The problem is now solved. Condor can be specified to inherit or not the shell
environment. Thanks everyone for your help.
【在 j*c 的大作中提到】 : The reason that I was writting a perl script is because I don't want to write : any shell script(actually I know very little about shell script). The specified : variables I want to know is "ARCH" or "OSTYPE" which always gives the type : of operation system (I need to invoke different binary and different parameter : files in my wrapper); and "USER", "HOSTNAME". : Thanks anyway, I will try to findout how to specify a shell in Condor.
|
j*c 发帖数: 97 | 7 good idea. but how to redirect the output of "uname" or "whoami" to
a scalar variable in perl?
【在 o***z 的大作中提到】 : 这些东东用uname -a之类的命令不能得到吗 : user可以用whoami或者$<($UID)
|
o***z 发帖数: 133 | 8 chomp($output=`uname -a`);
【在 j*c 的大作中提到】 : good idea. but how to redirect the output of "uname" or "whoami" to : a scalar variable in perl?
|
j*c 发帖数: 97 | 9 how comes this would work?
【在 o***z 的大作中提到】 : chomp($output=`uname -a`);
|
b****s 发帖数: 472 | 10 it work, haha.
actually you can call any shell command and get the output
in a scalar variablie like this.
like $list = `ls -l`
【在 j*c 的大作中提到】 : how comes this would work?
|
|
|
j*c 发帖数: 97 | 11 do you mean in perl?
I don't think so.
【在 b****s 的大作中提到】 : it work, haha. : actually you can call any shell command and get the output : in a scalar variablie like this. : like $list = `ls -l`
|
b****s 发帖数: 472 | 12 I've used it for a million times. It amost works for
every script language. why don't you try it by yourself?
【在 j*c 的大作中提到】 : do you mean in perl? : I don't think so.
|
j*c 发帖数: 97 | 13 I didn't try million times, only couple times yesterday. and it doesn't work.
in Perl a system call can only be done by "exec","system" or "syscall"
functions.
【在 b****s 的大作中提到】 : I've used it for a million times. It amost works for : every script language. why don't you try it by yourself?
|
o***z 发帖数: 133 | 14 i don't think exec or system can invoke a system call
`uname -a` can't either
【在 j*c 的大作中提到】 : I didn't try million times, only couple times yesterday. and it doesn't work. : in Perl a system call can only be done by "exec","system" or "syscall" : functions.
|
p******f 发帖数: 162 | 15 exec builtin -> exec(2)
system -> fork(2), exec(2) and waitpid(2)
qx or `` -> fork, exec, and waitpid
all of these will result in system calls, at least for *nix systems.
【在 o***z 的大作中提到】 : i don't think exec or system can invoke a system call : `uname -a` can't either
|
o***z 发帖数: 133 | 16 but they don't invoke system calls like
syscall(&SYS_write, fileno(STDOUT), $s, length $s);
【在 p******f 的大作中提到】 : exec builtin -> exec(2) : system -> fork(2), exec(2) and waitpid(2) : qx or `` -> fork, exec, and waitpid : all of these will result in system calls, at least for *nix systems.
|
w**n 发帖数: 88 | 17 It works for sure. the reason you can not do it successfully, I doubt
1. can you tell the difference between `` and ''
2, have you set your system path correctly.
BTW, be clear with the concept "system call", it is a special terminology
I don't think it means what you want it mean here ... and you make other
people confused.
【在 j*c 的大作中提到】 : I didn't try million times, only couple times yesterday. and it doesn't work. : in Perl a system call can only be done by "exec","system" or "syscall" : functions.
|
j*c 发帖数: 97 | 18 got it, I'm stupid. but I just find another complicated way to work out:
open(FH,'ls -l')
【在 w**n 的大作中提到】 : It works for sure. the reason you can not do it successfully, I doubt : 1. can you tell the difference between `` and '' : 2, have you set your system path correctly. : BTW, be clear with the concept "system call", it is a special terminology : I don't think it means what you want it mean here ... and you make other : people confused.
|
c*****e 发帖数: 32 | 19 "ls -l" shouldn't be working for sure, coz with '-l' the output will mess your
things up.
gotta be:
foreach my $file (`ls`){
#print "open FH, $file\n";
open (FH, $file) || die "can not open $file";
....... #your code goes here
.......
close (FH);
}
work.
【在 j*c 的大作中提到】 : got it, I'm stupid. but I just find another complicated way to work out: : open(FH,'ls -l')
|
p******f 发帖数: 162 | 20 why not glob or readdir, why turn to external "ls"?
【在 c*****e 的大作中提到】 : "ls -l" shouldn't be working for sure, coz with '-l' the output will mess your : things up. : gotta be: : foreach my $file (`ls`){ : #print "open FH, $file\n"; : open (FH, $file) || die "can not open $file"; : ....... #your code goes here : ....... : close (FH); : }
|
j*c 发帖数: 97 | 21 hehe, I was only giving an example of pipe in the output of an external command.
【在 p******f 的大作中提到】 : why not glob or readdir, why turn to external "ls"?
|
c*****e 发帖数: 32 | 22 Good point!
Thanks for reminding.
your
【在 p******f 的大作中提到】 : why not glob or readdir, why turn to external "ls"?
|