Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
veripuu
Posts: 2
Registered: ‎03-18-2013
My Device: Simulator

How to run linux commands like chmod ?

Greetings to all BB community!

 

I am trying to port my android app to BB. It includes a console binary which I run in thread and get its output. I need to "chmod 777" it before executing, because I copy it from assets to cache directory:

 

File f = new File(getCacheDir()+"/binary");
try {
 Process chmod = Runtime.getRuntime().exec("/system/bin/chmod 777 " +f.getPath());
 chmod.waitFor();
} catch(IOException e) { ... } catch(InterruptedException e) { ... }

 I run BB 10 Alpha simulator and get an error in Eclipse's Logcat "NullPointerException" in line inputThread.start(); below:

try {
 final ProcessBuilder builder = new ProcessBuilder(f.getPath());
 builder.redirectErrorStream(true);
 p = builder.start();

 in = p.getInputStream() ;
 out = p.getOutputStream ();

 printOut = new PrintWriter(out, true); // autoflush

 m_queue = new ArrayBlockingQueue<String>(10);
 inputThread = new InputThread(in, m_queue);
 inputThread.start(); // <-- ERROR

} catch(Exception e) { ... }

 If I understand correctly, there is no exec() on BB and chmod doesn't work, but how to get it to work?

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to run linux commands like chmod ?

Can you describe what you are trying to achieve and why you need to do it?  Perhaps we can think of a workaround or an alternative. 

 

Be aware that you can't run anything as a 'native' app on the BlackBerry.  Everything you can run has to be written in Java and executes in the JVM. 

Please use plain text.
Developer
simon_hain
Posts: 16,134
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to run linux commands like chmod ?

also note that BB10 does not have a java runtime, you mention the BB10 simulator.
If you want to ask about bb10 development best do it in the dedicated forums.

on bb java os there is no JNI.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Contributor
veripuu
Posts: 2
Registered: ‎03-18-2013
My Device: Simulator

Re: How to run linux commands like chmod ?

I am trying to run ELF binary compiled with GCC from C sources. On Android I simply use exec() or ProcessBuilder and it works great! I thought I can do same things on BB.
Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to run linux commands like chmod ?

[ Edited ]

On BB Java phones, this is not possible. 

 

If you are working on developing a BBOS 7 or earlier version in Java, then you will need to tell us what the binary actually does and we can give you some indication how you might achieve the same functionality in BBOS.  This is the right forum for that question. 

 

It might be possible on BB10 and then you have these choices

a) Try to use your current Android development and execute it using the runtime supplied

b) Rewrite everything in c/C++ native and use the c library externally.

c) Rewrite everything in c/C++/Cascades and use the c library externally.

 

That said, I still would doubt that it is possible to do this.  BB is much more secure than Android.  But if you were trying to develop for BB10, then you are in the wrong forum.  The right forum will depend on which development approach you were considering for BB10. 

Look here for the appropriate forum:

http://supportforums.blackberry.com/t5/Application-Platforms/ct-p/app_plat

Please use plain text.