Perl切换工作路径的问题
时间:2010-11-04
来源:互联网
大家好,
我使用perl执行一些shell命令,
比如
system("cmd1 ");
这个命令会创建一个文件夹,比如temp,
接下来,我要进入这个文件夹执行一些命令,我尝试
system("cd temp");
但是好像不成功,系统提示:
Can't exec "cd": No such file or directory at git.pl line 15
我想问问,使用perl如何切换当前的工作目录?
另外执行命令会有一些输出
如何把这些输出收集到我的日志文件里呢。
print LOG_HANDLE "log start \n";
谢谢!
我使用perl执行一些shell命令,
比如
system("cmd1 ");
这个命令会创建一个文件夹,比如temp,
接下来,我要进入这个文件夹执行一些命令,我尝试
system("cd temp");
但是好像不成功,系统提示:
Can't exec "cd": No such file or directory at git.pl line 15
我想问问,使用perl如何切换当前的工作目录?
另外执行命令会有一些输出
如何把这些输出收集到我的日志文件里呢。
print LOG_HANDLE "log start \n";
谢谢!
作者: hepower 发布时间: 2010-11-04
chdir
LOG输出也有相应模块,你也可以自己 print
LOG输出也有相应模块,你也可以自己 print
作者: zhlong8 发布时间: 2010-11-04
hi,
chdir已经搞定。
我的意思是
我执行一个cmd比如:
system("cmd"),会有一些输出信息在屏幕上打印出来,我怎么把这些信息打印到log文件里,我尝试:
print DB_LOG_FILE system("git log | grep Date");
但是失败了。。
谢谢!
chdir已经搞定。
我的意思是
我执行一个cmd比如:
system("cmd"),会有一些输出信息在屏幕上打印出来,我怎么把这些信息打印到log文件里,我尝试:
print DB_LOG_FILE system("git log | grep Date");
但是失败了。。
谢谢!
作者: hepower 发布时间: 2010-11-04
本帖最后由 zhlong8 于 2010-11-04 11:58 编辑
$str = `dir`
$str 里面即为 dir 的内容,注意是反引号
见 perlop
$str = `dir`
$str 里面即为 dir 的内容,注意是反引号
QUOTE:
qx/STRING/
`STRING`
A string which is (possibly) interpolated and then executed as a system command with /bin/sh or its equivalent. Shell wildcards, pipes, and redirections will be honored. The collected standard output of the command is returned; standard error is unaffected. In scalar context, it comes back as a single (potentially multi-line) string, or undef if the command failed. In list context, returns a list of lines (however you've defined lines with $/ or $INPUT_RECORD_SEPARATOR), or an empty list if the command failed.
`STRING`
A string which is (possibly) interpolated and then executed as a system command with /bin/sh or its equivalent. Shell wildcards, pipes, and redirections will be honored. The collected standard output of the command is returned; standard error is unaffected. In scalar context, it comes back as a single (potentially multi-line) string, or undef if the command failed. In list context, returns a list of lines (however you've defined lines with $/ or $INPUT_RECORD_SEPARATOR), or an empty list if the command failed.
见 perlop
作者: zhlong8 发布时间: 2010-11-04
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28