3

I want to run script file on android Shell using Native C program.

I tried using system function but it's not working.

result = system("sh ./test.sh");

LOGD("result is %d", result);

system command returns 0 means its not executed script file successfully.

test.sh contains

echo "test...."

Android NDK application could not print test.... when this system call runs.

Even any script can not be started using system call. i checked more than 10 different scripts.

test.sh have 777 permissions

Any help would be appreciated.

2
  • it should be result = system("sh ./test.sh"); say the dot before the blackslash Commented Mar 27, 2012 at 8:38
  • @blackbelt this command directly works so why its not working in system call Commented Mar 27, 2012 at 9:47

2 Answers 2

2

where is 'sh'? and what is your '.' current directory when the application runs? try:

result = system("/system/bin/sh /full/path/to/test.sh");

Sign up to request clarification or add additional context in comments.

5 Comments

test.sh is on my current direcory...I tired above command also but its not working
According to linux.die.net/man/3/system, if system() returns 0, then the command worked, otherwise it would be -1. Maybe the program runs but its output is not displayed for some reason? Try with a shell script that writes to a file ("echo test >> test1") and see if afterwards test1 exists...
I also tried this Option but its not working. i write one file using shell script using above command. but file not exits after using this
What if script wants input ? How to handle such situation?
@BRUCE Maybe an ugly workaround, but you could write that input to a temporary file and run a wrapper .sh that contains the line "test.sh < file".
0

Here i got the answer of this Question on Different post.

Run Shell Script file On Android Embedded Device using System function in Android NDK

thanks to all for Help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.