一起使用 Java 和 Cygwin 时需要一些帮助

发布于 2024-08-26 20:02:35 字数 716 浏览 5 评论 0原文

我是 javacygwin 的新手。我对两者都没有详细的了解。

我需要一些帮助..

我将按照简单的步骤尝试解释我的问题。

1)我正在开发tinyOS。其开源操作系统,用于无线传感器网络。它提供了用于通信(PC 到传感器)的 java 库

2)我正在通过 cigwin 在 windows xp 环境上工作。

3)我正在开发一个应用程序。该应用程序需要一个名为“Serial Forwarder”的 java 接口,该接口可以在提供的库中轻松获得。以前,我曾经手动启动此界面(通过输入命令**“java net.tinyos.sf.SerialForwarder”)**然后我的应用程序使用此界面。但现在我想让我的应用程序独立。用户需要了解此后台 cygwin 命令。

4)所以在我的java应用程序中我使用了

Runtime.getRuntime().exec(“java net.tinyos.sf.SerialForwarder)”。5

)这既没有给出任何错误也没有启动界面。

我的方向正确吗?
当我使用运行时执行命令时,如何确保通过 cigwin 接口调用该命令?

另外..如果我想编写.bat文件..我可以给出将要执行的命令..我如何确保这些命令是通过cigwin给出的..而不是通过cmd.exe给出的.. 请帮忙。我 。

I am new to java and also cygwin . I do not have in detailed knowledge of both .

I need some help..

I simple steps i will try to explain my problem.

1) I am working on tinyOS . its open source OS , used for wireless sensor networks. It provides java libraries to work on communication (PC to sensor)

2) I am working on windows xp environment through cigwin.

3) I am developing an application . THis application requires one java interface called "Serial Forwarder" , which is readily available in libraries provided. Previously i used to start this interface manually (by entering command **"java net.tinyos.sf.SerialForwarder ")**and then my application which uses this interface. But now i want to make my application independent . User need know about this background cygwin commands .

4) So in my java application i used

"Runtime.getRuntime().exec( "java net.tinyos.sf.SerialForwarder)" .

5) This i neither giving any error nor starting the interface.

Am I going on right way ?
When i am using runtime execute command , how can i make sure that this command is called through cigwin interface ?

Also .. if i want to write .bat file .. i which i can give commands which will be executed .. how can i make sure that those commands are given through cigwin .. and not through cmd.exe ..
Please help . me .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扮仙女 2024-09-02 20:02:35

抱歉,但有坏消息……带有 Cygwin 的 TinyOS 真的非常糟糕。即使你确实让事情正常工作,它也会非常缓慢且不可靠(除非 Cygwin 或 TinyOS 自从我上次使用它以来变得更好)。我强烈建议您下载 UbunTOS+VirtualBox(如果您需要在 Windows 上为 TinyOS 进行开发)。

也就是说,我会尽力帮助您...希望提高您的 Java、Cygwin 和 UNIX 知识...

1.) 明白了。
2.) 也发现了。
3.)

您可以编写一个 Java 程序,使用 JAR 中提供的类来执行您希望它执行的任何操作。如果您愿意,您可以使用 launch4j 或其他一些包装器将程序包装为可执行文件。虽然这确实没有必要。如果您愿意,您还可以创建一个调用 JAR 的 shell 脚本。

4.)

明白了。是的,调用另一个可执行文件并通过 PIPE 进行通信也是一种可能,尽管仅加载类并直接与其通信可能会更快。

5.)

它可能没有做任何事情,因为您没有给它任何命令行参数,并且 Process 它返回的对象具有 getInputStream() 和 getOutputStream() 方法,允许您与进程通信...该进程不会写入标准输出...它将写入管道。如果你想查看进程正在写入什么,那么你需要从 getInputStream() 返回的流中读取。

6.)

如果您使用 Cygwin,请不要使用批处理文件,而应使用 BASH shell 脚本(不需要扩展名,尽管有时会以“.sh”文件扩展名出现)。

Sorry, but there's bad news... TinyOS with Cygwin really, really sucks. Even if you do get things working, it will be very slow and unreliable (unless Cygwin or TinyOS got way better since I last used it). I highly recommend that you download UbunTOS+VirtualBox if you need to develop for TinyOS on Windows.

That said, I will try to help you out... hopefully improve your Java, Cygwin, and UNIX knowledge...

1.) Gotcha.
2.) Also gotcha.
3.)

You could write a Java program that uses the class provided in the JAR to do whatever it is you want it to do. You could use launch4j or some other wrapper to wrap your program as an executable, if you like. Although that really isn't necessary. You can also create a shell script that invokes your JAR if you like.

4.)

Gotcha. Yes, invoking another executable and communicating through a PIPE is also a possibility, although just loading the class and communicating with it directly will probably be faster.

5.)

It probably isn't doing anything since you haven't given it any commandline parameters, and the Process object that it returns has methods getInputStream() and getOutputStream() that allow you to communicate with the process... the process is not going to write to standard out... it is going to write to the pipe. If you want to see what the process is writing, then you need to read from the stream returned by getInputStream().

6.)

If you are using Cygwin, don't use a batch file, instead use a BASH shell script (doesn't need an extension, although it sometimes appears with the ".sh" file extension).

久夏青 2024-09-02 20:02:35

我可能误解了,或者过于简单化了,但你只是想在 Java 中运行 Java 程序?为什么不直接: net.tinyos.sf.SerialForwarder.main(new String[] {"foo", "bar"}); 您已经在使用 Java,只需调用该类的 main() 方法!

I may be misunderstanding, or oversimplifying, but you are simply trying to run a Java program from within Java? Why not just: net.tinyos.sf.SerialForwarder.main(new String[] {"foo", "bar"}); You're already in Java, just call the class's main() method!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文