failure of pipe in shell command, CGI scripting

Sadhunathan Nadesan sadhu at castandcrew.com
Sat Feb 9 19:02:00 EST 2002


This posting is for the benefit of the technical archives, regarding an
apparent problem I ran into, and worked around.  Not sure if this is
something I am doing wrong, or a problem with MC, Linux, or what.

Context
-------

Using MC as a cgi scripting language on RH Linux, to perform data base queries
via shell commands, and return search results as web pages.  The data base is
PostgreSQL, and each individual component of a command is proven to work fine.
This is Linux kernel 2.2.16, MC 2.4, PostgreSQL 6.5.3.

Problem
-------

When components are combined in a pipe line and submitted as a shell command, it 
stops working.  Same command run directly from the shell does work.


Work around/Solution
---------------------

Redirect SQL output to a file then cat the file into the RPT report formatter
program rather than trying to pipe directly from SQL into RPT.

Note:

Both methods have identical results when done from the shell directly,
but when submitted as MC shell commands, one method works, the other does not.

See example script below  (the line commented out is the one that fails).


#!/usr/local/bin/mc

on startup
  read from stdin until empty
  put urlDecode (it)  into formdata
  split formdata by "&" and "="
  put url "file:./by_date.sql" into the_query
  replace "$TALK_DATE" with formdata["talk_date"] in the_query
  put the_query into url "file:/tmp/by_date.sql"
  put "psql cybertalks -qt -f /tmp/by_date.sql > /tmp/date.dat; cat /tmp/date.dat| ./by_date.rpt" into command_string
  #put "psql cybertalks -qt -f /tmp/by_date.sql | ./by_date.rpt" into command_string
  put "Content-Type: text/html" & cr & cr
  set shellCommand to "/bin/sh"
  put shell(command_string)
end startup



More information about the metacard mailing list