Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6811879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:22:56+00:00 2026-05-26T20:22:56+00:00

I have a simple script written to process received email. Here are the tested

  • 0

I have a simple script written to process received email. Here are the tested scenarios:

A. Script function is to send an email indicating an email was received at piped address.

-tested by browser – Success

-tested by CLI – Success

-tested by piping – Success

B. Script function is to parse and write files to folder, AND send email indicating email was received at piped address

-tested by browser – Files written and email sent.

-tested by CLI – Files written and email sent.

-tested by piping – Files NOT written, BUT email is sent.

I have simplified the script to the basic function of reading and writing the piped message. I suspect the issue is a permission problem, but I can not find any supporting evidence.

I am not fluent in CLI, but can perform some task. I am not sure where to look for log files for the piped scenario.

Piping works just fine in all tested scenarios. Here is the simplified code that fails when invoked by piping:

#!/usr/bin/php -q
<?php
/* Read the message from STDIN */
$fd = fopen("php://stdin", "r"); 
$email = ""; // This will be the variable holding the data.
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
/* Saves the data into a file */
$fdw = fopen("/my/folder/mail.txt", "w");
fwrite($fdw, $email);
fclose($fdw);
/* Script End */

Thanks for any help.

Modified code to:

#!/usr/bin/php -q
<?php
/* Read the message from STDIN */
$email = file_get_contents('php://stdin');

/* Saves the data into a file */
$fdw = fopen("/Volumes/Cobra/Sites/email/mail.txt", "w+");
if (! $fdw) {
    error_log("Unable to open mail.txt for output.", 1, "myemail@mydomain.com", "From: admin@mydomain.com");
} else {
    fwrite($fdw, $email);
}

fclose($fdw);

/* Script End */

Error message was emailed. Now what? What user does the pipe-invoked script run as?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:22:57+00:00Added an answer on May 26, 2026 at 8:22 pm

    If it’s a permissions problem, then either fopen will return FALSE on failure. You’re not checking for that case, and assumes everything worked. Try

    $fd = fopen('php://stdin', 'r');
    if (!$fd) {
       die("Unable to open stdin for input");
    }
    
    $fdw = fopen(...);
    if (!$fdw) {
       die("Unable to open mail.txt for output");
    }
    

    If neither die() triggers, then it’s not a permissions issue.

    As one stylistic thing, unless your real code is much more complicated and does want to process stdin in chunks, you could just do:

    $email = file_get_contents('php://stdin');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a simple script that calls a function in a while loop.
This is a simple script I have written to test command line argument handling:
I have written a very simple bash script to help me migrate from dev
I have written a simple brainfuck interpreter in MATLAB script language. It is fed
I have written a very very very simple!! script in php. header redirection not
I have written a simple jQuery script that changes the hash tag of a
I am new to Python and I have written this simple script: #!/usr/bin/python3 import
I have written a simple jquery script for a content slider. My problem is
I have written a simple screen scraping script and at the end of the
I have written simple script: #!/bin/bash find . -name *.m4a | while read filename;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.