Forum OpenACS Q&A: Re: Can't exec a command in tcl page

Posted by Antonio Pisano on
Thanks for the many hints guys. Sadly no luck with this by now...

I need to convert csv to xls because I need an export function which could Just Work for a customer of ours. They expect a file to be loaded in their system to be an xls, so...

Anyway, I have tried redirecting standard error (and everything else) using &> /dev/null at the end of the command, but didn't work out (same error).

Catching the exec and ispecting its output shows a CHILDSTATUS error, but this we knew already.

I have also thought it could be a matter of different current folder, so I changed the command to

/usr/bin/libreoffice --headless --convert-to xls /tmp/fileugDbjI.csv --outdir /tmp

to force output folder to be /tmp. As before, the command works fine in the shell (return code is 0)

Using exec to invoke a shell as Neophytos suggested brings to the very same behaviour.

I am out of clues... think I will try to reproduce the problem on another server to see if it is due to this particular machine/configuration or if there is something going wrong with the proxy

Posted by Gustaf Neumann on
The hint with the CHILDSTATUS rings a bell. In case Neo's suggestion does not help, one more idea for debugging. Write a wrapper (e.g. named /tmp/ like the following
echo xxx `/usr/bin/id`
/usr/bin/libreoffice --headless --convert-to xls SOMEFILE.csv --outdir /tmp
echo "xxx $? exit code"
fill in a .csv tile for testing and call the wrapper via
set result [exec bash /tmp/]
i would not be wondering, when you get on your machine now a useful result now, showing a non-zero exit code from libreoffice. Maybe there is a permission problem under the userid of the server? Handing CHILDSTATUS in Tcl requires some special, which i don't see in nsproxy. Probably nsproxy has to be improved to return better errors.
Posted by Gustaf Neumann on
I've compared the cases, where tcl-exec and/or nsproxy-exec calls a program with a non-zero return status. In both cases, the behavior is the same, one gets the return status via the global variable ::errorCode. The following snippet shows the result code from the called program:
set cmd {/usr/bin/libreoffice ... --outdir /tmp}
if {[catch {set result [exec {*}$cmd]} errorMsg]} {
   lassign {*}$::errorCode code id value
   if {$code eq "CHILDSTATUS"} {set result "program exited with code $value"}
so, the nsproxy behavior is technically correct, just the error message from tcl could be better. What return code do you get in your installation?
Posted by Benjamin Brink on
Gustaf writes:

"Maybe there is a permission problem under the userid of the server."

I've had this happen before.

Antonio, what happens if you use a different directory using server's owner and group same as openacs system, such as a openacs-4/tmp/ ?