How do I specify the path when I place the Batch File on the server?

Asked 2 years ago, Updated 2 years ago, 106 views

I would like to launch the batch file from php.

exec("cmd.exe /c(drive name)aaa.bat";

If aaa.bat is on the php server
as is usually the case with What happens to the pass designation?
Also, if it is on a particular folder on a program in the bat file,
What should I do?

 copy (drive name) aaa.txt (drive name) bbb.txt

Thank you for your cooperation.

Add

I think the local environment is Windows, but what is the operating system of php's server?

It's like Linux.

php batch-file

2022-09-30 18:08

1 Answers

As a pre-file path issue, you cannot run cmd.exe directly on Linux because the executable file format is different on Windows and Linux operating systems.Since the server running php is Linux, the file to run with the exec function must be an executable file in the Linux format.There is an indirect way to run cmd.exe on Linux, but it does not solve this problem efficiently.

What is called a batch file in Windows is called a shell script in a typical Linux operating system.If you really want to run an external script, you will have to write a shell script and run it via a shell such as sh or bash.

But as a matter of fact, why do you want to run an external script? Can't you write it as a php program? If you can write it as a php program, you can absorb the difference between batch files and shell scripts.For example, you can copy files using php's copy() function.

Based on these assumptions, you can specify the file using the Linux file path method on top of the Linux OS.


2022-09-30 18:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.