2013-08-30 66 views
1

運行的mysqldump時,這是我的代碼:mysqldump的錯誤代碼6通過Java

String cmd = "\"C:\\Program Files\\MySQL\\MySQL Server 5.6\\bin\\mysqldump\" -h www.anonymizeddomain.com -u root -proot anon_thisdb > anon_thisdb.sql\""; 
      Process proc = Runtime.getRuntime().exec(cmd); 
      Print(cmd); 

      InputStream stdin = proc.getInputStream(); 
      InputStreamReader isr = new InputStreamReader(stdin); 
      BufferedReader br = new BufferedReader(isr); 

      String line = null; 
      System.out.println("<OUTPUT>"); 

      while ((line = br.readLine()) != null) 
       System.out.println(line); 

      System.out.println("</OUTPUT>"); 
      int exitVal = proc.waitFor(); 
      System.out.println("Process exitValue: " + exitVal); 

退出,錯誤代碼爲6和IDK的原因。我從控制檯得到的輸出是這樣的:

<OUTPUT> 
-- MySQL dump 10.13 Distrib 5.6.13, for Win64 (x86_64) 
-- 
-- Host: www.anonymizeddomain.com Database: anon_thisdb 
-- ------------------------------------------------------ 
-- Server version 5.5.32-cll-lve 

/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */; 
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */; 
/*!40101 SET @[email protected]@COLLATION_CONNECTION */; 
/*!40101 SET NAMES utf8 */; 
/*!40103 SET @[email protected]@TIME_ZONE */; 
/*!40103 SET TIME_ZONE='+00:00' */; 
/*!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 
/*!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 
/*!40101 SET @[email protected]@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 
/*!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0 */; 
</OUTPUT> 
Process exitValue: 6 

什麼冰棒片我做錯了?

我把字符串中的轉義字符,所以我不會得到錯誤,但我得到的錯誤:\軟糖? :\

+0

[mysqldump從java運行時返回代碼6的可能的重複,但相同的命令從命令行正常工作](http://stackoverflow.com/questions/15463990/mysqldump-returns-code-6-when-run -java-but-the-same-command-works-fine-fro) –

回答

1

這是你正在尋找我的朋友

https://stackoverflow.com/a/15464074/1639291

問候什麼!

+0

有趣且有意義。 – Matthew

+0

我已經試過這個,但是這個在控制檯中返回的是''C:\ Program''不被識別爲內部或外部命令, 可操作的程序或批處理文件。「 – user2734304

+0

你是否把\「逃脫?發生,因爲它只讀取** C:\ Program **而不是** C:\ Program Files ... **,並且唯一讀取它的方法是將其放入在「」之間 – JGutierrezC