dracoblue.net

Simple php task to run commandline in phing

In phing there is a task called

exec. Even though it provides a "passthru"-property it's not really possible to directly get the response from the output.

Since I wanted to have direct output of all data, I created an adhock-task called "run". You can add it to your phing build file, by adding this tag right before the usage.

<adhoc-task name="run">
class RunTest extends Task {
        private $dir;
        private $command;

        function setCommand($command) {
                $this->command = $command;
        }

        function setDir($dir) {
                $this->dir = $dir;
        }

        function main() {
                $this->log("Changing to: " . $this->dir);
                chdir($this->dir);
                $this->log("Executing: " . $this->command);
                system($this->command);
        }
}
</adhoc-task>

Remember, that this task does not check wether the directory exists and always requires it to be set. If you want to extend the task for your needs and mind to share it, feel free to post a reply!

In phing, php by
@ 22 Sep 2009, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About