Atitit.執行cli cmd的原理與調試

Atitit.執行cli cmd的原理與調試php

 

1/c  /k 1html

2/k  參數,有利於調試 1java

3-------code 2python

4打開程序後與openner脫離關係 3shell

5返回參數 StandardOutput  StandardError 3windows

6Bat參數的隱藏命令::使用@後頭符 3api

6.1. 1.1. 實際執行模式 3iphone

6.2. 1.2. 空格的問題 3ide

6.3. 1.3. 中文路徑的問題,程序文件讀取編碼設置 3post

6.4. 1.4. 回顯亂碼 4

7雙引號轉譯問題 4

8參數 4

 

1. /c  /k

。若是使用 cmd/c 就能夠省掉 EXIT 

2. /k  參數,有利於調試

使用process explorer能夠看到實際的調用參數

 

做者:: 老哇的爪子 Attilax 艾龍,  EMAIL:1466519819@qq.com

轉載請註明來源: http://blog.csdn.net/attilax

 

 

 

Atitit.執行cmd的原理與調試

"cmd.exe"  /k  "D:\workspace3 空格\amaz_spider\WpfApplication1/phprun.bat"  "D:\workspace22 空格\amaz_spider\WpfApplication1/com.attilax/api.php"  "tagP823=1&textfield=2015-9-1&textfield2=09%253A10&prod_name=iphone%2bcase&select=%25E6%258E%2592%25E5%2590%258Dxy&select3=%25E6%258E%2592%25E5%2590%258Dxy&select4=%25E5%25A5%25BD%25E8%25AF%2584&select5=%25E5%25A5%25BD%25E8%25AF%2584&select6=%25E8%25B7%259F%25E5%258D%2596%25E4%25B8%25AA%25E6%2595%25B0&select9=%25E8%25B7%259F%25E5%258D%2596%25E4%25B8%25AA%25E6%2595%25B0&select7=%25E5%25A5%25BD%25E8%25AF%2584%25E6%2595%25B0%25E7%259B%25AE&select8=%25E5%25A5%25BD%25E8%25AF%2584%25E6%2595%25B0%25E7%259B%25AE&select2=%25E5%25BA%2597%25E9%2593%25BA%25E8%25AF%2584%25E4%25BB%25B7%25E6%2595%25B0&select10=%25E5%25BA%2597%25E9%2593%25BA%25E8%25AF%2584%25E4%25BB%25B7%25E6%2595%25B0&method=search_context&$callback=search_context_finish&$parser=php"

 

3. -------code

    public class Cmd

    {

        private Process proc = null;

        /// <summary>

        /// 構造方法

        /// </summary>

        public Cmd()

        {

            proc = new Process();

        }

        /// <summary>

        /// 執行CMD語句

        /// </summary>

        /// <param name="cmd">要執行的CMD命令</param>

        public string RunCmd(string cmd)

        {

            proc.StartInfo.CreateNoWindow = true;

            proc.StartInfo.FileName = cmd;

                //"cmd.exe";

            proc.StartInfo.UseShellExecute = false;

           proc.StartInfo.RedirectStandardError = true;

           proc.StartInfo.RedirectStandardInput = true;

           proc.StartInfo.RedirectStandardOutput = true;

      //      proc.StartInfo.Arguments = " /k  " + cmd;//「/C」表示執行完命令後立刻退出   

           

            proc.Start();

            proc.WaitForExit();//這裏無限等待進程結束  

     //     proc.StandardInput.WriteLine(cmd);

       //     proc.StandardInput.WriteLine("exit");

            string outStr = proc.StandardOutput.ReadToEnd();

            string errstr = proc.StandardError.ReadToEnd();

            Console.WriteLine(errstr);

            proc.Close();

            return outStr;

        }

 

4. 打開程序後與openner脫離關係

應該使用cmd /c ???

 

5. 返回參數 StandardOutput  StandardError

 

    string outStr = proc.StandardOutput.ReadToEnd();

            string errstr = proc.StandardError.ReadToEnd();

 

6. Bat參數的隱藏命令::使用@後頭符

6.1.     1.1. 實際執行模式

Processmonitor 檢查。獲得。。

PID: 115372, Command line: cmd.exe /c "D:\workspace 絀烘牸\AtiBrow\exp_receipt.bat"

6.2. 1.2. 空格的問題

雙引號解決

6.3. 1.3. 中文路徑的問題,程序文件讀取編碼設置

Php.ini中的default_charset = "utf-8"  只是設置postget的編碼,不能設置php文件的讀取編碼。。最好是註釋掉此參數,讓他根據文件自己的編碼自動判斷,不然輸出的php結果都 header('Content-Type:text/html;charset=utf8

 

做者:: 老哇的爪子 Attilax 艾龍,  EMAIL:1466519819@qq.com

轉載請註明來源: http://blog.csdn.net/attilax

 

 

緣由在於php文件自己是用系統字符集來編碼的,中文的windows XP都是用GB2312,每個文件頭部都有字段指示該文件是用何種方式編碼的

 

javac編譯java源文件時,編譯器默認用系統編碼讀源文件裏的內容。若是源文件不是用系統編碼來保存的,能夠用命令javac -encoding指定具體的編碼

 

淋巴,只能不個php文件的編碼設置成gbk。。才ok。。

 

6.4. 1.4. 回顯亂碼

 

 header('Content-Type:text/html;charset=gbk');  

 

7. 雙引號轉譯問題

好像是三個雙引號   

8. 參數

執行 CMD 時,參數加引號常見問題 的米-漠石's Blog - 博客頻道 - CSDN.NET.html

C#執行DOS命令(CMD命令) 楊友山 博客頻道 - CSDN.NET

paip.asp vbs經過CLI命令行調用PHP代碼 - attilax的專欄 博客頻道 - CSDN.NET

paip.執行shell cmd 命令uapi java php python總結 - attilax的專欄 博客頻道 - CSDN.NET

paip.python 執行shell 帶空格命令行attilax總結- python教程 中國黑帽網.html

Atitit.執行cmd 命令行 php - attilax的專欄 博客頻道 - CSDN.NET.html

相關文章
相關標籤/搜索