Opened 5 years ago
Closed 4 years ago
#300 closed enhancement (fixed)
ExecTask should return command output as a property (different from passthru)
| Reported by: | anonymous | Owned by: | mrook |
|---|---|---|---|
| Priority: | low | Milestone: | 2.4.0RC1 |
| Component: | phing-tasks-system | Version: | 2.3.2 |
| Keywords: | exec, output | Cc: |
Description
I'm writing a Web control panel for basic operating system commands, so I constantly need to parse up output of 'ls', 'grep', 'ifconfig' and the like. There is currently no way to return the output of an ExecTask. This is virtually unneeded for normal phing usage, but it is highly desirable for embedded phing applications.
I have supplied a patch to add a simple output property that closely mirrors the "returnProperty"
example usage:
<target name="extendedstatus">
<exec command="/etc/init.d/httpd extendedstatus" outputProperty="command.out"/>
</target>
Then the application which starts the target can access the "command.out" property and deal with it.
Attachments (1)
Change History (7)
Changed 5 years ago by anonymous
comment:1 Changed 5 years ago by anonymous
ticket should have been labelled "enhancement"
comment:2 Changed 5 years ago by anonymous
With the patch submitted, doing:
<exec command="echo Hello; echo World" outputProperty="cmd_output"/>
<echo msg="Output: ${cmd_output}"/>
Results in:
[exec] Executing command: echo Hello; echo World 2>&1
[echo] Output: Array
Rather than:
[exec] Executing command: echo Hello; echo World 2>&1
[echo] Output: Hello
World
The fix for this is to change the added setProperty line from:
$this->project->setProperty($this->outputProperty, $output);
to:
$this->project->setProperty($this->outputProperty, implode("\n", $output));
(Assuming multi-line cmd output should remain multi-line)
comment:3 Changed 5 years ago by anonymous
Currently, I only hand off the returned property back to controlling PHP scripts. I don't use the command later in the build file.
But, I don't see a problem with this. My controlling script could just as easily explode the $output back into an array if necessary. I was just trying to modify phing as little as possible.
comment:4 Changed 4 years ago by mrook
- Milestone set to 2.4.0
- Owner changed from hans to mrook
- Status changed from new to assigned
- Type changed from defect to enhancement
comment:5 Changed 4 years ago by mrook
comment:6 Changed 4 years ago by mrook
- Resolution set to fixed
- Status changed from assigned to closed
The patch was applied, with the addition of the implode() call. Thanks!

patch to add output property to system exec task