Skip to main content

Runtime.getRuntime().exec() doesn't work

27 replies [Last post]
mkant
Offline
Joined: 2010-02-03

Hello,

I write an application with phonme advanced.
But the function Runtime.getRuntime().exec("...") doesn't work.
It comes the Exception: IOException: Not supported by platform

Should phoneme advanced support this function?

Thank you.

Have anybody a solution for me. I want to execute a .exe-File.

Best regards,

Mathias

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mkant
Offline
Joined: 2010-02-03

I think it looks like that:

I think I can't click the button in the Dialog. So no event is thrown.

Message was edited by: mkant

davyp
Offline
Joined: 2007-01-03

May I suggest to start a new thread because it is about a different topic.

Also, I am not sure I understand you correctly, so if you have a code example,
that would help to explain and reproduce the problem.

Davy

mkant
Offline
Joined: 2010-02-03

edit: it is a Dialog, which is open in my problem. And in this Dialog is a Panel with the numbers.

mkant
Offline
Joined: 2010-02-03

in version pMEA b151 it works.

mkant
Offline
Joined: 2010-02-03

The problem is, that we doesn't have Visual C++ 2005, so I can't compile it.

Can anybody compile it for me? Or must I do it on my pc?

I know this is is a big request, but I need it.

Thank you.

Mathias

jldominguez
Offline
Joined: 2008-01-02

Hello.
I can compile it easily. What is the package name you would like to have?
Regards,
Juan Lucas

mkant
Offline
Joined: 2010-02-03

de.igosys.mobileforms.utils

jldominguez
Offline
Joined: 2008-01-02

I have nt tested it on a PDA, but I think it'll work:

http://www.prodevelop.es/files/fm/public/downloads/processes_dll_java.zip

Regards,
Juan Lucas

mkant
Offline
Joined: 2010-02-03

It works.

Thank you very very much.

Without opening a new topic:

Why can the user resize my Frames, although I have set resizable(false)?
How can I prevent the resize?

davyp
Offline
Joined: 2007-01-03

The WinCE implementation in cdc/src/share/personal/native/awt/pocketpc/PPCWindowPeer.cpp
does not support it. In the current code, the method has no effect when WINCE is defined:

void AwtWindow::SetResizable(BOOL isResizable)
{
if (IsEmbedded()) {
return;
}
#ifndef WINCE
long style = GetStyle();
static const long SizeStyles = WS_THICKFRAME|WS_MAXIMIZEBOX|WS_MINIMIZEBOX;

if (isResizable) {
style |= SizeStyles;
} else {
style &= ~SizeStyles;
}
SetStyle(style);
RedrawNonClient();
#endif /* WINCE */
}

Perhaps there was a technical reason why this feature was disabled for WinCE.

Davy

mkant
Offline
Joined: 2010-02-03

So it isn't possible at all?

davyp
Offline
Joined: 2007-01-03

If I have time, I will check what happens if I remove the macro definition test and enable
the feature in the next build.

Davy

davyp
Offline
Joined: 2007-01-03

setResizable() should work now in the latest builds.

Davy

mkant
Offline
Joined: 2010-02-03

Thanks. That works.

But, in the newiest build one of my action Listener do not work.

Have changed something in the last 2 or 3 builds?

It doesn't work only at one position: I have a frame with a textfield. when the focus come in, a new frame with numbers open. Normally, when I click a number, this I can see in the textfield.

You know what I mean?

Mathias

Message was edited by: mkant

jldominguez
Offline
Joined: 2008-01-02

Hello mkant.

I have the JNI method and DLL that you need. You have to do this:

- add this class to your Java application with EXACTLY the same package name (es.prodevelop.gvsig.mobile.common.ProcessUtils.java)

http://subversion.gvsig.org/gvSIG-mobile/pilots/branches/pilot2/appGvsig...

- download this DLL and copy it to a folder in your PDA where you have other DLLs or create it if you are not using any DLL (for example \myapp\lib)

http://subversion.gvsig.org/gvSIG-mobile/pilots/branches/pilot2/resource...

- in the parameters to start your app, you have to add:

-Djava.library.path=\myapp\lib

so the application will find the file processes.dll

Then, if you want to start the web browser, you only have to call from you Java code:

ProcessUtils.startOrForeground("XXX", "iexplore.exe", "");

I think EXE files under \Windows do not need the full path. If you have other EXE out of \Windows, use the full path.

(this has worked on Windows Mobile 2003, 5, 6, 6.1 and 6.5)

I hope I didn't forget any detail ;)

Regards,
Juan Lucas

mkant
Offline
Joined: 2010-02-03

Thank you very much. This works!

Only one question: Is ther a possibility, to change the package name? This package name doesn't match to our package name conventions.

jldominguez
Offline
Joined: 2008-01-02

Hello.

Unfortunately, the package name is hardcoded in the JNI C++ source code, so you'll have to compile it again.

The steps are:

- You need Microsoft Visual C++ 2005 or higher

- You need to have a .../include/jni.h file somewhere in your computer that corresponds to the target platform. I have used the jni.h from IBM J9 and it seems to work (perhaps Davy or Hinkmond can indicate where to get the file jni.h)

- Install a SVN client (for example in Eclipse) and connect to:

URL: http://subversion.gvsig.org/gvSIG-mobile

Download (check out) this folder:

/pilots/trunk/JNI_Sep_2009/processes

The file "processes.sln" is the MS VC++ project file.

- Open that project from MS VC++ and edit the .h and .cpp files to have your favorite package name. Change the dependency that points to the jni.h file indicating the one you have in your PC. Compile the project and you should get a new file processes.dll

Regards,
Juan Lucas

jldominguez
Offline
Joined: 2008-01-02

Hello. I forgot to mention that Microsoft Visual C++ 2005 or higher needs to have the SDK for your device:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=...

I used the Pocket PC 2003 SDK and works for any version of Windows Mobile (probably because it's a very smple DLL)

Regards,
Juan Lucas

Hinkmond Wong

phonemeadvanced@mobileandembedded.org wrote:
> But the function Runtime.getRuntime().exec("...") doesn't work.
> It comes the Exception: IOException: Not supported by platform
>
> Should phoneme advanced support this function?
>
> Thank you.
>
> Have anybody a solution for me. I want to execute a .exe-File.
>

Hi Mathias,

Unfortunately, it is not a mandatory rule that a phoneME Advanced
implementation must support the Runtime.getRuntime().exec("") method
call. What you are seeing is proper on some operating systems.

There are plenty of mobile and embedded OSes that cannot or will not
allow a platform (such as phoneME Advanced) on top if it, to arbitrarily
execute binary (executable) files because of security or robustness
concerns.

Instead, you should try to reimplement whatever the .exe file does, in
Java technology.

Hinkmond

---------------------------------------------------------------------
To unsubscribe, e-mail: advanced-unsubscribe@phoneme.dev.java.net
For additional commands, e-mail: advanced-help@phoneme.dev.java.net

mkant
Offline
Joined: 2010-02-03

My problem ist, that I want to execute another program on th e mobile device.

I think, it is not very easy to implement this in java technology.

Exist any phoneme advanced version, where I can run this function?

PS I use Windows Mobile.

Thank you.

Best regards,

Mathias

Message was edited by: mkant

davyp
Offline
Joined: 2007-01-03

See what happens when you specify the full path of the executable as in
exec("\\windows\\iexplore.exe"). If you don't specify the full path, Windows
Mobile is looking for the program in the root of the file system.

Davy

mkant
Offline
Joined: 2010-02-03

it doesn't work. The same exception is coming.

davyp
Offline
Joined: 2007-01-03

You are right. I can confirm the problem.

I have not checked where the exception is thrown, but I guess it is just an implementation
issue. I know calling external programs is possible as I have done so for implementing the
platformRequest() method in phoneME Feature.

Davy

mkant
Offline
Joined: 2010-02-03

And what does it mean for me?

davyp
Offline
Joined: 2007-01-03

That it currently does not work, and after going through the code, it will probably never
fully work if you look at the execInternal code in cdc/src/win32/native/java/lang/Runtime_md.c

#ifdef WINCE
{
/* The Process class requires an implementation that supports
* streams between processes (stdin, stdout, and stderr), while
* on Wince there is no notion of console I/O or pipes between
* processes.
*/
JNU_ThrowIOException(env, "Not supported by platform");
return 0;
}
#else
...

Merely executing an application is not a problem, but the input/output redirection will
not work on WinCE. What you could do is implement a simple JNI native wrapper yourself
around the native CreateProcess method:

http://msdn.microsoft.com/en-us/library/ms939168.aspx

The implementation should look something like this:

void callProgram() {
STARTUPINFO si;
PROCESS_INFORMATION pi;

memset(&si, 0, sizeof(si));
si.cb = sizeof(si);

if (CreateProcess(NULL, _T("\\windows\\iexplore.exe"), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
} else {
printf("Error: Spawning a process failed");
}
}

Davy

mkant
Offline
Joined: 2010-02-03

Sorry, but I do not understand this.

I can not call the createProcess method in my code. My Editor doesn't find it.

Can you explain your solution a little bit in detail?

Thank you very much.

Mathias

davyp
Offline
Joined: 2007-01-03

The CreateProcess method is a native Windows Mobile API, and that is why your editor
does not recognize it (it is not a Java method). You would have to make a JNI wrapper around
that method so you can call it from within your Java application.

Basically what you do is declare a Java method as 'native', compile the Java application,
generate a C header file and implement the native method in C. This native code (of which
I have shown a very rough implementation) would have to be cross-compiled with the Microsoft
toolchains (eVC4 or Visual Studio will do) into an ARM DLL and this library needs to be loaded
by your java application.

If you are not that familiar with JNI, have a look at:
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jni.html

Davy