Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何输入命令提示符,即';从批处理文件、java应用程序运行_Java_Windows_Batch File_Command Prompt - Fatal编程技术网

如何输入命令提示符,即';从批处理文件、java应用程序运行

如何输入命令提示符,即';从批处理文件、java应用程序运行,java,windows,batch-file,command-prompt,Java,Windows,Batch File,Command Prompt,我想知道是否有一种方法可以输入到命令提示符,即从一个执行的批处理文件,从一个java程序运行。我有一个计时器,早上9点开始,晚上9点结束。。我让批处理启动,但当我希望它停止时,我无法让“停止”进入命令提示符以启动批处理文件命令。请帮忙,谢谢 public class Main extends Voids{ String start = "09:00:00 AM"; String end = "09:00:00 PM"; public Main() { try {

我想知道是否有一种方法可以输入到命令提示符,即从一个执行的批处理文件,从一个java程序运行。我有一个计时器,早上9点开始,晚上9点结束。。我让批处理启动,但当我希望它停止时,我无法让“停止”进入命令提示符以启动批处理文件命令。请帮忙,谢谢

public class Main extends Voids{
String start = "09:00:00 AM";
String end = "09:00:00 PM";
public Main()
{
    try
    {
        int x = 1;
        while(x == 1)
        {
            x = 2;
            if(x == 2)
            {
                SimpleDateFormat ft = new SimpleDateFormat ("hh:mm:ss a");
                Date date = new Date();
                System.out.println(ft.format(date));
                Thread.sleep(1000);
                if(ft.format(date).equals(stime))
                {
                    Runtime.getRuntime().exec("cmd /c start start.bat");
                    Thread.sleep(43200000);
                    try{
                        Runtime runtime = Runtime.getRuntime();
                        Process process = runtime.exec("stop"); // you might need the full path
                        InputStream is = process.getInputStream();
                        InputStreamReader isr = new InputStreamReader(is);
                        BufferedReader br = new BufferedReader(isr);
                        String line;

                        while ((line = br.readLine()) != null) {
                            System.out.println(line);
                        }
                        }catch(Exception e)
                        {
                            e.getStackTrace();
                        }
                }else
                {
                    x = 1;
                }
            }
        }
    }catch(Exception e)
    {
        System.out.println("EXCEPTION: \n");
        e.getStackTrace();
    }
}
批次:

@ECHO off
cls
:start
ECHO Enter "stop" to end session
set /p choice=:
if '%choice%'=='' ECHO "%choice%" is not valid please try again
if '%choice%'=='stop' goto stop
ECHO.
goto start
:stop
ECHO STOPPING SESSION
pause
exit

您已经有一个
InputStream
。现在,以类似的方式获取一个
OutputStream
,然后简单地对其进行写入。

真正的问题是,为什么您要使用批处理,而不仅仅是从系统中使用java进行处理。in@Quirliom因为我想看看这是否适用于外部文件,而不仅仅是使用java。只是在玩弄java。:)