derphil
derphil

Reputation: 385

Php popen only returns bool(true) instead of a pointer

I'm wondering that my simple popen() call only returns the boolean value TRUE instead of a resource.

Therefore the following fputs() throws a warnings like "Warning: fputs() expects parameter 1 to be resource, boolean given [...]"

As described in the Php manual, I expect a resource/pointer or FALSE in return.

Here is my example:

$path = 'C:\path\to\oracle\product\11.2.0\server\bin\sqlplus.exe';
$ph = popen($path,'w') || die ("Program not found");
fputs($ph, "username/password"\n");

Can anybody help?!

Upvotes: 0

Views: 101

Answers (2)

Oebele
Oebele

Reputation: 591

Using the || syntax is still possible, just add parentheses to the first half.

($ph = popen($path,'w')) || die ("Program not found");

Upvotes: 0

Prasanth Bendra
Prasanth Bendra

Reputation: 32800

Change :

$ph = popen($path,'w') || die ("Program not found"); to $ph = popen($path,'w');

remove everything after || and try.

Also there is extra quote here : fputs($ph, "username/password"\n"); remove one fputs($ph, "username/password\n");

Upvotes: 1

Related Questions