批量失败输出长度限制

时间:2015-08-28 16:08:27

标签: java batch-file output stdout

我正在尝试通过Java中的Runtime类运行批处理文件。

echo "It is a test"
echo  "line3"
echo  "line4"
echo  "line5"
echo  "line6"
echo  "line7"
echo  "line8"
echo  "line9"
echo  "line10"
echo  "line11"
echo  "line12"
echo  "line13"
echo  "line14"
echo  "line15"
echo  "line16"
echo  "line17"
echo  "line18"
echo  "line19"
echo  "line20"
echo  "line21"
echo  "line22"
echo  "line23"
echo  "line24"
echo  "line25"
echo  "line26"
echo  "line27"
echo  "line28"
echo  "line29"
echo  "line30"
echo  "line31"
echo  "line32"
echo  "line33"
echo  "line34"
echo  "line35"
echo  "line36"
echo  "line37"
echo  "line38"
echo  "line39"
echo  "line40"
echo  "line41"
echo  "line42"
echo  "line43"
echo  "line44"
echo  "line45"
echo  "line46"
echo  "line47"
echo  "l....."

test.bat的

C:\test.bat >> C:\output.txt 2>&1

脚本失败,似乎是对输出的数据量有限制。如果我在文件开头使用@echo off,输出限制似乎会增加。我还测试运行与此 C:\app\aime\gc_inst\user_projects\domains\GCDomain>echo "line3" "line3"C:\app\aime\gc_inst\user_projects\domains\GCDomain>echo "line4" "line4"C:\app\aime\gc_inst\user_projects\domains\GCDomain>echo "line5" "line5"C:\app\aime\gc_inst\user_projects\domains\GCDomain>echo "line6" "line6"C:\app\aime\gc_inst\user_projects\domains\GCDomain>echo "line7" "line7"C:\app\aime\gc_inst\user_projects\domains\GCDomain>echo "line8" "line8" 相同的批处理文件命令,它可以工作。将输出重定向到.txt使脚本运行没有错误。有没有人有内心为什么会发生这种情况?是否有解决方法来增加可输出的数据量?

我从控制台运行java可执行文件。平台是Windows 7。 感谢。

Outout就是这个:

   <?php


class CheckFolder{

    public function getSubFolders($dir)
    {
        $folders = array();
        $ffs = scandir($dir);
        foreach($ffs as $ff)
        {
            if($ff != '.' && $ff != '..')
            {
                if(is_dir($dir.'/'.$ff))  $folders[] = $ff;
            }
        }
        return $folders;      
    }

    public function getFiles($dir)
    {
        $files = array();
        if(is_dir($dir))
        {
            $ffs = scandir($dir);
            foreach($ffs as $ff)
            {
                if($ff != '.' && $ff != '..')
                {
                    if(!is_dir($dir.'/'.$ff))  $files[] = '<li>'.$ff.'</li>';
                }
            }
        }
        return $files;
    }    

    function listFolderFiles($dir)
    {
        $ffs     = scandir($dir);
        $folders = $this->getSubFolders($dir);
        $files   = $this->getFiles($dir);

        if(strpos($dir, '/') >0)
        {
            $folderName = substr($dir, strrpos($dir, '/') + 1);
        }
        else
        {        
            $folderName =   $dir;
        }
        echo '<ul>';
        echo '<li>'.$folderName.'</li>';
        if(count($files) > 0)
        {   
            echo '<ul>';
            foreach($files as $file)
            {
                // /echo '<li>'.$file.'</li>';
                echo $file;
            }
            echo '</ul>';
        }

        echo '</ul>';

        foreach($folders as $folder)
        {
           // echo '<li>'.$folderName.'</li>';
            $this->listFolderFiles($dir.'/'.$folder); 
        }

    }


}

$dir = 'test';
$folder = new CheckFolder();
$folder->listFolderFiles($dir)

?>

它刚刚结束。

1 个答案:

答案 0 :(得分:0)

通过cmd.exe尝试。

Runtime.getRuntime().exec(new String[] {"cmd.exe", "/c", "C:\\test.bat"});

我通常也会使用ProcessBuilder