为什么';t Java解释>;在shell命令中?

为什么';t Java解释>;在shell命令中?,java,mysql,command-line,Java,Mysql,Command Line,我使用以下命令从命令行导入mysql备份- mysql -hlocalhost -uroot -pmysql dpfinal < /home/kshitiz/Desktop/dbdump.sql mysql命令不是解释stdin重定向的命令(Look here:这是一个常见问题解答。重定向由shell解释。@devnull Java不会将命令传递给shell?@kshitizzarma Java会将命令传递给shell,但其传递方式会导致shell解释。除此之外,命令行选项需要是传递给R

我使用以下命令从命令行导入mysql备份-

mysql -hlocalhost -uroot -pmysql dpfinal < /home/kshitiz/Desktop/dbdump.sql

mysql
命令不是解释stdin重定向的命令(
Look here:这是一个常见问题解答。重定向由shell解释。@devnull Java不会将命令传递给shell?@kshitizzarma Java会将命令传递给shell,但其传递方式会导致shell解释
。除此之外,命令行选项需要是传递给
Runt的命令行数组中的单独条目ime.exec(新字符串[]{“sh”、“-c”、“mysql-hlocalhost-uroot-pmysql dpfinal
您可以使用-D和-e选项运行sql脚本:
mysql-hlocalhost-uroot-pmysql-D dpfinal-e“source dbdump.sql”
@Nos也不起作用。并且没有输出。@TajMorton也可以从命令行工作,但不能从Java工作。
String command = "mysql -hlocalhost -uroot -pmysql dpfinal < /home/kshitiz/Desktop/dbdump.sql";
InputStream is = Runtime.getRuntime().exec(command).getInputStream();
InputStreamReader ir = new InputStreamReader(is);
BufferedReader br = new BufferedReader(ir);
String s = br.readLine();
while(s!= null) {
    System.out.println(s);
    s = br.readLine();
}
mysql  Ver 14.14 Distrib 5.5.28, for debian-linux-gnu (i686) using readline 6.2
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Usage: mysql [OPTIONS] [database]
  -?, --help          Display this help and exit.
  -I, --help          Synonym for -?
  --auto-rehash       Enable automatic rehashing. One doesn't need to use
                      'rehash' to get table and field completion, but startup
                      and reconnecting may take a longer time. Disable with
                      --disable-auto-rehash.
                      (Defaults to on; use --skip-auto-rehash to disable.)
  -A, --no-auto-rehash 
                      No automatic rehashing. One has to use 'rehash' to get
                      table and field completion. This gives a quicker start of
                      mysql and disables rehashing on reconnect.
  --auto-vertical-output 
                      Automatically switch to vertical output mode if the
                      result is wider than the terminal width.
  -B, --batch         Don't use history file. Disable interactive behavior.
                      (Enables --silent.)
  --character-sets-dir=name 
                      Directory for character set files.
  --column-type-info  Display column type information.