Modify

Opened 6 years ago

Closed 5 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)

08_add_output_to_phing_exec.diff (1016 bytes) - added by anonymous 6 years ago.
patch to add output property to system exec task

Download all attachments as: .zip

Change History (7)

Changed 6 years ago by anonymous

patch to add output property to system exec task

comment:1 Changed 6 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 5 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 5 years ago by mrook

(In [513]) Refs #300 - ExecTask should return command output as a property

comment:6 Changed 5 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!

Add Comment

Modify Ticket

Action
as closed The owner will remain mrook.
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.