Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
633 views
in Technique[技术] by (71.8m points)

command - How to use pipe (" | ") in PHP exec?

I can use CMD to execute two commands at the same time using:

command1 | command2

In PHP, I assumed it should work, but it doesn't:

Shell_exec("command1 | command2 ");

How do I fix it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try to add braces:

shell_exec("(command1 | command2)");

There is a comment in the PHP documentation that does some I/O-redirection with popen.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...