How to interact with STDIN/STDOUT?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sjordan
Forum Newbie
Posts: 1
Joined: Thu Nov 20, 2008 4:24 pm

How to interact with STDIN/STDOUT?

Post by sjordan »

I am attempting to connect to a host via webdav. Other protocols such as FTP are not an option. I don't have the option of building in any optional/third-party wrappers, such as PHP WebDAV. However, the system I am connecting from does have cadaver.

From the shell, I interact with cadaver as follows:
$> cadaver somehost.com
Authentication required for Documents access on server `somehost.com':
Username: <username>
Password:
dav:/fileserver/client/> quit
Connection to `somehost.com' closed.
My question:

How, from within a php script, do I interact with the shell or STDIN/STDOUT in this post-response manner? I wish to invoke cadaver via something like the following pseudo-code:

Code: Select all

 
// open stream
$resource = shell_exec to open connection stream with cadaver;
 
// push username to stream;
put($resource, 'username');
 
//  push password to stream;
put($resource, 'password');
 
// if successful push standard cadaver commands to stream
get($resource, 'some_file.txt');
 
Thanks in advance
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: How to interact with STDIN/STDOUT?

Post by Syntac »

PHP provides the constants STDIN, STDOUT, and STDERR for command-line usage. However, these aren't as flexible as actual stream resources, so try this:

Code: Select all

$fp = fopen("php://stdin", "r");
If you need non-blocking input, there are a few ways, but I'm too tired to dig 'em up.
Post Reply