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

查看:29
本文介绍了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 调用是否创建了一个全新的 shell(没有环境变量设置)?我怎样才能避免这种情况?

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 元字符,如果有,则将整个参数传递给系统的命令 shell 进行解析(在 Unix 平台上为/bin/sh -c,但在其他平台上有所不同).如果参数中没有 shell 元字符,则将其拆分为单词并直接传递给 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.此外,shell 是否加载了您的 .bashrc、.profile 或 .bash_profile 取决于 shell 是否是交互式的.可能不是,但您可以检查 这个.

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天全站免登陆