Atitit. Execute cmd command line PHP

Source: Internet
Author: User

Atitit. Execution cmd command Line PHP

1. Execute the cmd command line and invoke the base of the system command 1

1.1. Actual Execution Mode 1

1.2. Questions about Spaces 1

1.3. Chinese path problem, program file read encoding settings 1

1.4. Echo Garbled 2

2. Exec,system and other functions call system commands 2

3. PHP.ini, turn off safe mode Safe_mode = off 3

4. Reference 3

1. Implementationcmdcommand line, the basis for invoking system commands1.1. Actual execution mode

Processmonitor check. Get..

pid:115372, Command line:cmd.exe/c "D:\workspace characters \atibrow\exp_receipt.bat"

1.2. Questions about Spaces

Double Quote Resolution

1.3. Chinese path problem, program file read encoding settings

PHP.ini in default_charset = "Utf-8" just set post,get encoding, Cannot set read code for PHP file: It is best to comment out this parameter, let him according to the encoding of the file itself automatically judge, otherwise the output PHP results are header (' Content-type:text/html;charset=utf8

Author:: Old Wow's paw attilax Ayron, email:[email protected]

Reprint please indicate source: Http://blog.csdn.net/attilax

The reason is PHP The file itself is encoded using the system character set, the Chinese Windows XP It's all used GB2312 , each file header has a field that indicates how the file is encoded.

When compiling Java source files with Javac, the compiler reads the contents of the source file by default in the system code. If the source file is not saved with system encoding, you can specify the specific encoding with the command javac-encoding

Lymphatic, only not a PHP file encoding set to GBK. Just OK.

1.4. Echo garbled

Header (' CONTENT-TYPE:TEXT/HTML;CHARSET=GBK ');

2. Exec,systemsuch as function call System command

These two are all used to invoke the system Shell command,

Different points :

  exec You can return all the results of the execution to $output in the function ( array ), $status is the state of execution 0 for Success 1 to fail

  systerm no need to provide $output function, he was directly returning the result, the same $return _var is the execution of the status code 0 for Success 1 to fail

  exec Example :

1. The following is the reference content :

2. <?php

3. $a = Exec ("dir", $out, $status);

4. Print_r ($a);

5. Print_r ($out);

6. Print_r ($status);

7.?>

  system Example :

1. The following is the reference content :

2. <?php

3. $a = System ("dir", $out);

4. Print_r ($a);

5. Print_r ($out);

6.?>

3. php.ini, turn off safe mode.Safe_mode = Off

First, turn on php.ini, turn off safe mode Safe_mode = off, and then look at the list of disabled functions disable_functions = Proc_open, Popen, exec, System, shell_exec, remove exec.

4. Reference

PHP uses functions such as Exec,system to call system commands . htm

Apache and PHP default encoding Problem Resolution (detailed)_php Chase _ Sina blog . htm

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Atitit. Execute cmd command line PHP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.