开发者

Some help required while working on Java and Cygwin together

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 m开发者_如何转开发y 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 .


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).


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜