Hi,
just to clarify the problem and script
del /p d:\133.mht
dir
deletes the file but ask for keyboard input ("/P Give a Yes/No Prompt
before deleting"). The prompt is displayed so far but the file is not
deleted and directory is listed (whcih should not be the case).
I played around with it and have the following solution (tester under
Mac OS X)
>>> Snippet >>>
ByteArrayInputStream bais = new
ByteArrayInputStream("Y\n".getBytes());
CommandLine cl = new CommandLine(stdinSript);
PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(
System.out, System.err, bais);
Executor executor = new DefaultExecutor();
executor.setStreamHandler(pumpStreamHandler);
assertTrue(executor.execute(cl) == 0);
assertFalse(new File("./target/to-be-deleted.xml").exists());
<<<
>>> stdin.sh >>>
mkdir target
cp pom.xml target/to-be-deleted.xml
ls -l target
rm -i target/to-be-deleted.xml
ls -l target
<<<
Can you check if that would also work under Windows? In general the
redirection causes a lot more problems on Windows compared to Unix.
Cheers,
SIegfried Goeschl
On 12.08.10 04:49, 刘东 wrote:
> Hi all,
> When I use commons-exec to call os script like .bat on windows,I meet
> problem.
> the bat script like this:
>
> del /p d:\133.mht
> dir
>
> When use commons-exec to call this,There no pause after "del /p
> d:\133.mht",and "dir" command execute.
> The code shows as follow:
> File testDir = new File(
> "D:/eclipse_works/exec/opensource/exec/src/test/scripts");
> File testScript = TestUtil.resolveScriptForOS(testDir + "/test");
> File printArgsScript = TestUtil
> .resolveScriptForOS(testDir + "/deltest");
>
>
> ByteArrayOutputStream baos = new ByteArrayOutputStream();
> PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(baos,
> baos);
> pumpStreamHandler.start();
>
> Executor exec = new DefaultExecutor();
> exec.setStreamHandler(pumpStreamHandler);
> // exec.setStreamHandler(new PumpStreamHandler(baos, baos));
> CommandLine cl = new CommandLine(printArgsScript);
> exec.execute(cl);
> System.out.println("out===== " + baos.toString().toString());
>
> when run:
> out=====
> D:\eclipse_works\exec>del /p d:\133.mht
> d:\133.mht,要删除(Y/N)吗?
>
> D:\eclipse_works\exec>dir
> 驱动器 D 中的卷没有标签。
> 卷的序列号是 C850-03F6
>
> D:\eclipse_works\exec 的目录
>
> 2010-08-10 20:35<DIR> .
> 2010-08-10 20:35<DIR> ..
> 2010-08-10 20:38 495 .classpath
> 2010-08-10 20:35 380 .project
> 2010-08-10 20:35<DIR> .settings
> 2010-08-10 20:38<DIR> bin
> 2010-08-10 20:35<DIR> opensource
> 2010-08-10 20:35<DIR> src
> 2 个文件 875 字节
> 6 个目录 13,176,107,008 可用字节
>
>
> how to resolve this problem?
> thanks ahead
>
> 2010-08-12
>
>
>
> 刘东
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]