JasonDavis
JasonDavis

Reputation: 48973

How to make command line tool work in windows and linux?

Making my PHP Command line application support Linux and Windows. Currently it has this code below to work from command line on Linux/unix

How can I make it work on Windows? I lan on having a setting to determine if the sytem is Linux or Windows and using the correct commands based on that but I do not know how to make these function below work in Windows

exec() is a PHP function to run stuff through the command line

exec("rm -f $dest_file", $var);

exec("mv $quant_file {$this->tmp_path}/{$src_filename}-quant.png");

Upvotes: 0

Views: 381

Answers (1)

Lior Cohen
Lior Cohen

Reputation: 9055

You could test which platform you're on using the PHP_OS constant and run commands accordingly.

I would, however, suggest that you use the PHP provided filesystem functions (if possible).

Here are some links:

http://www.php.net/manual/en/ref.filesystem.php

http://www.php.net/manual/en/ref.dir.php

Upvotes: 1

Related Questions