Shell command copy file

pluton

Active Member
Licensed User
Longtime User
Hi
I'm doing some app which need to copy one .txt file to my other app.

I execute command as super user and file succesfully copies into dir but the file is empty (0 bytes)

What I'm missing. Here is my code:

B4X:
Dim file1, file2 As String

Other code:
B4X:
Sub GoGoGo

   file1 = File.Combine(File.DirAssets, "source.txt")
   file2 = "data/data/com.myother.app/files/destination.txt"
   PokreniShell("cat" &file1 &" > " &file2)
   
End Sub

Start command:
B4X:
Sub PokreniShell (comando As String)
Dim Command, Runner As String
Dim StdOut, StdErr As StringBuilder
Dim Result As Int
   Runner = File.Combine(File.DirInternalCache, "runner")
    Command = File.Combine(File.DirInternalCache, "command")
    File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
    File.WriteString(File.DirInternalCache, "command", comando & CRLF & "exit") 'Any commands via crlf, and exit at end 
    StdOut.Initialize
    StdErr.Initialize
    Result = ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
    Msgbox(StdOut.tostring, "")
End Sub
 

pluton

Active Member
Licensed User
Longtime User
In error I see problem is in path

B4X:
file1 = File.Combine(File.DirAssets, "source.txt")

It says:
AssetsDir/source.txt: No such file or directory

But file is there
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I think DirAssets is a more virtual directory, the linux shell might not be able to access it.
Try copying to DirInternal first using File.Copy, and then copy from there.

EDIT:
Also the documentation of File.Combine says: This methods does not support files in the assets folder.
 
Last edited:
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Yes that is it

Thank you
This solved my problem:

B4X:
File.Copy(File.DirAssets,"source.txt",File.DirInternal,"source.txt")
   file1 = File.Combine(File.DirInternal, "source.txt")
 
Upvote 0
Top