android - what is the correct way to concat strings in c++ and execute using system -


the following code used in native c++ library create directory under android shell,

jniexport void jnicall java_com_xprea_lib_stb_mkdir(jnienv* env, jobject javathis, jstring jdir) { const char* dir = (env)->getstringutfchars(jdir, 0);     string d=dir; string cmd= "su -c 'mkdir -p "+d+"'"; const char* c=cmd.c_str(); loge("s%s",c); system(c);  } 

it's not working because command built concatenated strings. tested without concatenation , it's working

what correct way concat strings , send them system()

your concatenation "su -c 'mkdir -p "+d+"'" results in string

su -c 'mkdir -p bla' (if dir name bla)

so command su searches command named mkdir -p bla won't find. better make:

"su -c mkdir -p '"+d+"'" concatenation. way search command named mkdir find, , directory name may contain white space (although have escape ' , \ character \.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -