问题描述
我对系统函数有问题.我想将系统功能输出存储到变量中.
I have a problem with the system function. I want to store the system functions output to a variable.
例如,
system("ls");
在这里,我希望当前目录中的所有文件名都存储在一个变量中.我知道我可以通过将输出重定向到文件中并从中读取并将其存储到变量中来做到这一点.但是我想要一种比这更有效的方法.有什么办法.
Here I want all the file names in the current directory to store in a variable. I know that I can do this by redirecting the output into a file and read from that and store that to a variable. But I want a efficient way than that. Is there any way .
推荐答案
否,您不能存储ls输出的值,由于系统始终将命令作为子进程执行,因此,请尝试使用反引号"command",它会在当前命令中执行命令处理本身!
No, you cannot store the values of the ls output ,since system always execute the command as a child process ,so try with backtick `command` which executes the command in the currentprocess itself!
这篇关于如何将Perl的系统函数输出存储到变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!