java Runtime.exec()程序和传递字符到getch() [英] java Runtime.exec() programm and pass character to getch()

查看:143
本文介绍了java Runtime.exec()程序和传递字符到getch()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从java运行ffmpeg作为外部进程。几分钟后,我想阻止它。
它要求我点击'q',它在控制台中工作,但是当我尝试使用java将'q'写入其stdin(process.getOutputStream())时,它不起作用。



我只需要c,使用ASCII字符集将其转换为字节,将其写入流中,将其清空并关闭它,Ffmpeg不会停止。



我简要地看了它的来源,发现它使用getch()函数,它是(根据手册)从关联终端读取字符。



/ p> ffmpeg也可以通过信号停止,但是在Windows中也不起作用。



有没有人知道如何解决我的问题?
$ b

是的,我真的想要运行ffmpeg作为外部程序,我知道关于xuggle,但它对我来说不起作用,我需要裸机ffmpeg,我不想自己写JNI现在。



谢谢!

解决方案

从终端键盘读取一个字符,而不是输入流!
在* nix中,它使用ioctl,in窗口(我相信)某种控制台API。



看起来我不能从JNI中停止ffmpeg从java((


I want to run ffmpeg from java as external process. After several minutes I want to stop it. It asks me to click 'q', and it works in console, but when I try to write 'q' to its stdin (process.getOutputStream() using java -- it does not work.

I just take "c", convert it to byte using ASCII charset, write it to the stream, flush it and close it. Ffmpeg does not stop.

I briefly looked in its sources, and found that it uses getch() function which is (according to manual) "reads character from associated terminal".

ffmpeg could also stop by signal, but it does not work in windows too.

Does anybody know how to solve my issue?

And yes: I do really want to run ffmpeg as external program. I know about xuggle, but it does not work for me, I need bare ffmpeg, and I do not want to write JNI myself now.

Thank you!

解决方案

See, readch() reads one character from terminal keyboard, not input stream! In *nix it uses ioctl, in windows (I believe) some kind of Console API.

Looks like I can't stop ffmpeg from java with out of JNI:(

这篇关于java Runtime.exec()程序和传递字符到getch()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆