如何将命令提示符输出存储到perl中的veri中 [英] How to store command prompt output into the veriable in perl

查看:87
本文介绍了如何将命令提示符输出存储到perl中的veri中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

我正在尝试将命令提示符输出存储到veriable中.
我在命令提示符下运行一些命令,该命令以单个值以及多个值给出输出.我想将这些值存储到数组变量中.但是我不知道如何获取命令提示符输出.

有人知道怎么做吗?
我正在谷歌上搜索,但没有得到任何有用的解决方案.

解决方案

http://www.well.ox.ac.uk/~johnb/comp/perl/intro.html#execunix [ Google [ ^ ].


简单的方法是使用反引号:

  


list =`ls -al`;



-这将在一个变量中为您提供命令输出.如果希望将其拆分为行数组:

  @ list  = 拆分 


Hi Friends,

I am trying to store the command prompt output in to the veriable.
I am running some commands on command prompt which gives output in single value as well as in multiple values. I want to store those values into the array variable. But I dont know how to fetch the command prompt output.

Could anybody have an idea how to do it?
I am googling on it but didnt get any usefull solution yet.

解决方案

http://stackoverflow.com/questions/2415954/how-can-i-store-perls-system-function-output-to-a-variable[^]
http://www.well.ox.ac.uk/~johnb/comp/perl/intro.html#execunix[^]

Google[^] for more.


The simple way is to use backticks:


list = `ls -al`;



- that will give you the command output in one variable. If you want it split into an array of lines:

@list = split


这篇关于如何将命令提示符输出存储到perl中的veri中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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