B4J Question Problem with file.exists

HARRY

Active Member
Licensed User
I use the following code to test jShell for fswebcam :

B4X:
'Non-UI application (console / server application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region
Sub Process_Globals
End Sub
Sub AppStart (Args() As String)
Dim shl As Shell
    If File.Exists("/home/pi/MyApps/Domo","Webcam.jpg") = True Then
        File.Delete("/home/pi/MyApps/Domo","Webcam.jpg")
    End If
  
   shl.Initialize("shl", "/usr/bin/fswebcam",     Array As String("-r 800*600"," -s 2","--no-banner", " /home/pi/MyApps/Domo/Webcam.jpg"))
   shl.Run(10000) 'set a timeout of 10 seconds
   StartMessageLoop 'need to call this as this is a console app.
End Sub


Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
   If Success AND ExitCode = 0 Then
     Log("Success")
     Log(StdOut)
   Else
     Log("Error: " & StdErr)
   End If
   ExitApplication
End Sub

A couple of times it worked, but suddenly File.Exists returned false, whereas the file really exists and is listed e.g. by rasbian File Manager. When the result is not correct executing the program reports that the fswebcam program cannot be found with the message:

Error: org.apache.commons.exec.ExecuteException: Execution failed (Exit value: -559038737. Caused by java.io.IOException: Cannot run program "\usr\bin\fswebcam" (in directory "."): CreateProcess error=2, Het systeem kan het opgegeven bestand niet vinden)


What can be the cause of this behaviour?

Harry
 

FabioRome

Member
Licensed User
test well

B4X:
If File.Exists("/home/pi/MyApps/Domo/","Webcam.jpg") = True Then
  File.Delete("/home/pi/MyApps/Domo/","Webcam.jpg")
End If
 

HARRY

Active Member
Licensed User
Hallo FabioRome,

The / makes no difference. Anyhow, fswebcam is not found for some reason , but it is really located in /usr/bin.

Harry
 

HARRY

Active Member
Licensed User
'you' is the B4J program. How can it get root permission?

Remember, it worked before!

For the FileExist I can imagine that root permission is required, as to access the contents only the owner has the right.

For fswebcam Anybody has the execution right.

Can I force fswebcam to create an image file with all rights to Anybody?
 

HARRY

Active Member
Licensed User
Hi,

I continued exercising. I removed the FileExist and rebooted the raspberry. Then one single time the program run was successfull, next run the 'normal' result as mentionned before. Again reboot and failure the first time I tried the program.
 

HARRY

Active Member
Licensed User
With RunSynchonous I get additional information:

Program started.
Error occurred on line: 15 (main).
java.io.IOException: Cannot run program "fswebcam" (in directory "."): CreateProcess error=2, Het systeem kan het opgegeven bestand niet vinden
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at org.apache.commons.exec.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:58)
at org.apache.commons.exec.DefaultExecutor.launch(DefaultExecutor.java:254)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:319)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:160)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:147)
at anywheresoftware.b4j.objects.Shell.RunSynchronous(Shell.java:126)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:606)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:227)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:82)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
at b4j.example.main.main(main.java:29)
Caused by: java.io.IOException: CreateProcess error=2, Het systeem kan het opgegeven bestand niet vinden
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1022)
... 22 more
Harry
 
Top