CFEXECUTE Errata

Description

We should be able to do better than CFEXECUTE.
1) CommandResults should include the exitValue() from the Process object. We should be able to further provide that back to the calling page. Getting the exit or return value from a process is pretty standard for anything calling external programs. Perhaps instead of having a variable, and an errorVariable, and an exitValue - we should just return a results structure, i.e. like cfhttp would. Especially since outputFile and errorFile gain nothing, because Command is just going to gobble the entire stream into memory anyway. (If it were going to instead redirect to a file, I might think differently.)

2) Provide an option to actually stream directly to a file. I don't know how big the output from a cfexecute-d process will be... in my case, usually less than 100 lines, so gobbling the stream into memory is fine. But anything returning thousands of lines or something memory significant should stream directly to disk first.

3) Providing arrays for arguments, environment, pretty much anything ProcessBuilder has supported since Java 7, without just band-aiding the parser by turning the array back into a string before execution.

4) Timeout not specified or 0 makes cfexecute useless. cfdocs.org does NOT indicate what happens when timeout<=0, but Adobe docs do - it goes into "non blocking" mode, which essentially means "Spawn a thread and return immediately"... While it's tied to the page context, no future is returned to the calling page, so you cannot check the progress of the process. I'd prefer it be blocking personally, but if it is going to do be non-blocking, we should return a future that wraps the PageContextThread and interfaces w/ the Process object so we can have truly USEFUL non-blocking.

For that matter, if something requires input or output, being able to interact with that non-blocking process would be pretty awesome. Use the future to "print" to the STDIN stream, and receive on-the-fly results from the buffered STDOUT stream, instead of assuming the process is a one-shot batch-mode no-stdin deal. (i.e. Perl https://perldoc.perl.org/IPC/Open3.html, or http://expectj.sourceforge.net/)

Since this diverges from Adobe's cfexecute semantics we're probably talking about a different, better, lucee-specific function or functions.

Activity

Show:

Brad Wood 12 May 2021 at 14:49

Some additional thoughts regarding improvements from switching to Processbuilder (copied from a Slack convo)

  • working directory support

  • Be able to pass raw args via array directly (no escaping and no quotes necessary!!!)

  • control over environment variables of the process

  • access to exit codes

  • better control over waiting for the process to end/destroying it

  • We could even provide a feature to pass a UDF to process text as it streamed out

JP 16 November 2018 at 22:29
Edited

This is an excellent feature request! Returning additional information, including error codes, would be very helpful.

I'm currently struggling with the limitations of cfexecute right now as I'm trying to hand off execution from Lucee to CommandBox asynchronously (set timeout to 0), while at the same time being able to verify that the command was handed off correctly. Setting the timeout to 0 works, but if there's a syntax error or some other problem in my command, I will never know because cfexecute does not wait for errors in this mode.

As a workaround, I'm setting a very low timeout (1 second) and terminateontimeout=false, which throws an exception if there was a problem with my command syntax or otherwise can't execute my command. Unfortunately it will also throw an exception when the timeout is reached. It would be nice to be able to catch a timeout error explicitly: `catch (timeout err) {}`

FYI, the error I get when I create a bad command (invalid batch file) is:

Error invoking external process Cannot run program "mytest.bat": CreateProcess error=2, The system cannot find the file specified

Could cfexecute return after it executes `CreateProcess`? Ideally it would return a success code even when my timeout is 0.

was helping me with this, has implemented some CLI run code for commandbox, and might have some insight here.

Joseph Gooch 2 October 2018 at 14:55

Should solve arguments=SomeArray as well - ideally by passing the array of arguments all the way through untranslated

Details

Assignee

Reporter

Labels

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Priority

Created 2 October 2018 at 14:54
Updated 12 May 2021 at 14:49