Perl system()调用使用哪个shell? [英] Which shell does a Perl system() call use?

查看:90
本文介绍了Perl system()调用使用哪个shell?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用系统调用来执行一些任务

I am using a system call to do some tasks

system('myframework mycode');

但是它抱怨缺少环境变量. 这些环境变量是在我的bash shell(我运行Perl代码的位置)中设置的.

but it complains of missing environment variables. Those environment variables are set at my bash shell (from where I run the Perl code).

我在做什么错了?

system调用是否创建一个全新的外壳程序(没有环境变量设置)?我该如何避免呢?

Does the system call create a brand new shell (without environment variable settings)? How can I avoid that?

推荐答案

这很复杂. Perl不一定调用shell. Perldoc 说:

It's complicated. Perl does not necessarily invoke a shell. Perldoc says:

如果只有一个标量参数,则检查该参数是否包含shell元字符,如果有,则将整个参数传递至系统的命令外壳程序进行解析(在Unix平台上为/bin/sh -c,但在其他平台上会有所不同).如果参数中没有外壳元字符,则将其拆分为单词,然后直接传递给execvp,这样效率更高.

If there is only one scalar argument, the argument is checked for shell metacharacters, and if there are any, the entire argument is passed to the system's command shell for parsing (this is /bin/sh -c on Unix platforms, but varies on other platforms). If there are no shell metacharacters in the argument, it is split into words and passed directly to execvp , which is more efficient.

因此,实际上看起来您已将参数直接传递给execvp.此外,外壳程序是否加载了.bashrc,.profile或.bash_profile,取决于该外壳程序是否是交互式的.可能不是,但是您可以像这个.

So it actually looks like you would have the arguments passed right to execvp. Furthermore, whether the shell loaded your .bashrc, .profile, or .bash_profile depends on whether the shell is interactive. Likely it isn't, but you can check like this.

这篇关于Perl system()调用使用哪个shell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆