php 将字符串传递给外部 diff 命令
我的程序生成两个字符串,我希望通过外部 diff 工具对它们进行比较。 diff 工具仅接受文件/目录作为参数。这是 diff file1 file2
工作正常,但 diff "hello" "world"
不起作用。有没有办法将我的字符串直接传递给 diff
而不创建任何临时文件?谢谢。
My program generates two strings and I want them compared by the external diff tool. The diff tool accepts only files/directories as arguments. That's diff file1 file2
works perfectly but diff "hello" "world"
doesn't work. Is there a way to pass my strings directly to diff
without creating any temporary files? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在外壳上,您可以使用临时管道。
使用反引号运算符或任何其他方法在 php.ini 中执行命令。有关执行命令的详细信息,请参阅手册: http://www.php.net /manual/en/ref.exec.php
确保正确转义字符串。
编辑:此功能称为临时管道。因此 shell 将其转换为文件描述符。
有关详细说明,请参阅 http://www.linuxjournal.com/article/2156?page=0,1" rel="nofollow">http://www.linuxjournal.com/article/2156?页=0,1
On the shell, you can use temporary pipes.
Use the backticks operator or any other method to execute the command in php. For details on executing commands, see the manual: http://www.php.net/manual/en/ref.exec.php
Make sure, you properly escape the strings.
EDIT: This feature is called temporary pipes. So the shell translates it to a file descriptor.
For a detailed explanation see http://www.linuxjournal.com/article/2156?page=0,1