0

The APK is written in RAD Studio C++Builder 11.2.

For example, I have tried a lot of methods but I get compile errors.

The code looks like:

UnicodeString command = "test_run"; 
TFileName fullPath = TPath::Combine(TPath::GetDocumentsPath(), command);

TProcess* process = new TProcess(NULL);
process->Executable = fullPath;

TStreamReader* output = new TStreamReader(process->Output);
process->Execute();
Memo1->Lines->Add(output->ReadLine());
output->Free();
process->Free();

TProcess doesn't exist in RAD Studio 11.2.

Another way:

#define TArray System::TArray__1
#define TJavaArray TJavaArray__1
#define JString Androidapi::Jni::Javatypes::_di_JString

JString jCommand = StringToJString("test_run");  
JString jOutput = StringToJString(""); 
TArray<System::Byte> *jResult = NULL; 

try {
    _di_JRuntime rt = TJRuntime::JavaClass->getRuntime();
    _di_JProcess proc = rt->exec(jCommand);  
    _di_JInputStream is = proc->getInputStream(); 
    TJavaArray<System::Byte> *jdata = new TJavaArray<System::Byte>(1024);
    while (is->available() > 0) {
        int count = is->read(jdata,0,jdata->Length);
        jOutput = jOutput + JStringToString(TJString::JavaClass->init(jdata,count));
    }
    jResult = new TArray<System::Byte>(jdata);
} catch (...) {
    ShowMessage("Error: cannot run command");
    jOutput = "";
}

Gets stucked in JRuntime.

I have no idea how to run a console command using the FMX framework.

Can anyone help?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
DarkSpy
  • 91
  • 5
  • `TProcess` is a FreePascal class, you are correct that it doesn't exist natively in RADStudio. There is a [Delphi port](https://github.com/z505/TProcess-Delphi/blob/master/dprocess.pas) of it available, but it appears to support only Windows and OSX, not Android. As for `JRuntime`, what problems are you having with that, exactly? Please be more specific. – Remy Lebeau Apr 15 '23 at 17:09
  • On a side note, you should not call `JStringToString()` on arbitrary bytes in a loop, you can corrupt multibyte characters that way. Gather all of the byyes first, then convert to a single string. Also, why are you converting bytes to a Delphi `String` but then appending that to an Android `JString`? Also, your `jResult` will not contain all of the received bytes, only the bytes from the last loop iteration. – Remy Lebeau Apr 15 '23 at 17:15
  • @RemyLebeau thanks, the JRuntime error is _di_JRuntime and _di_JProcess not exists. i had searched all "rtl / fmx / ctl" include files but not found _di_JProcess or _di_JRuntime keywords in it. – DarkSpy Apr 16 '23 at 00:59

0 Answers0