B4J Question Execute Shell .exe from within Files app?

MathiasM

Active Member
Licensed User
Hello

I try execute an exe file with the shell. This is the code I'm using:

B4X:
sh.Initialize("split", File.Combine(File.DirAssets, "cpdf.exe"), Array As String("-split", txtPDFPath.Text, "-o", File.Combine(File.DirTemp & SplittedPDFFolder, "page%%%%%.pdf")))
    sh.Run(10000)
    Wait For split_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
    Log(StdOut)
    Log(StdErr)

So I'm trying to launch cpdf.exe in the Assetfolder. But I get this error:
org.apache.commons.exec.ExecuteException: Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "AssetsDir\cpdf.exe" (in directory "."): CreateProcess error=2, The system cannot find the file.)

The odd thing is, the file is certainly in the folder:


I tried another way, specifying the workingdirectory:

B4X:
sh.Initialize("split", "cpdf.exe", Array As String("-split", txtPDFPath.Text, "-o", File.Combine(File.DirTemp & SplittedPDFFolder, "page%%%%%.pdf")))
    sh.WorkingDirectory = File.DirAssets
    sh.Run(10000)

However, that also throws an error (but another)

Does anyone know what's wrong? Thanks for any insights.
 

MathiasM

Active Member
Licensed User
Hi Enrique

Thanks, your solution works. For future reference, this is my working code:
B4X:
File.Copy(File.DirAssets, "cpdf.exe", File.DirApp, "cpdf.exe")
Dim sh As Shell
sh.Initialize("split", "cpdf.exe", Array As String("-split", txtPDFPath.Text, "-o", File.Combine(File.DirTemp & SplittedPDFFolder, "page%%%%%.pdf")))
sh.WorkingDirectory = File.DirApp
sh.Run(10000)
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…