B4J Question JShell working directory

walterf25

Expert
Licensed User
Longtime User
Hello all, i'm trying to run a python script using the JShell library on a Mac computer, the script runs just fine if I run it through a command line, i'm trying to figure out how to run it from a Java application using the Jshell library.

In the command line if I use the following command the python script runs fine.
~/.snaptools_virtualenvs/snaptools_0.0.21/bin/python temp_stream_with_init_oct10.py --inward_leds --
delay_sec 1 --ble Specs_45698c

Additionally how can i switch directories using Jshell in Mac, i'm not very familiar with Mac computers, i'm strictly a windows guy, but this java application i'm working on needs to work on a Mac computer.

What is the working directory property used for, I know you can assign a directory but is it the directory where your python framework is installed on, or where the python script is located?

Thanks all in advance for all the help.

Walter
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
What is the working directory property used for, I know you can assign a directory but is it the directory where your python framework is installed on, or where the python script is located?
This is the process working directory. It is similar to starting a process from the terminal while you are currently in the working directory.

Where is your code? What are the values of StdOut and StdErr?
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
This is the process working directory. It is similar to starting a process from the terminal while you are currently in the working directory.

Where is your code? What are the values of StdOut and StdErr?
Sorry, here's the code i've tried so far

B4X:
shell.Initialize("shell","~/.snaptools_virtualenvs/snaptools_0.0.21/bin/python", "python temp_stream_with_init_oct10.py", "--inward_leds", "--delay_sec 1",  "--ble Specs_45698c")
shell.RunWithOutputEvents(10000)

The StrdErr output just tells me that it can't find such directory.

Thanks,
Walter
 
Last edited:
Upvote 0

walterf25

Expert
Licensed User
Longtime User
This is the process working directory. It is similar to starting a process from the terminal while you are currently in the working directory.

Where is your code? What are the values of StdOut and StdErr?
I actually got it sort of working today, but for some reason when i pass the parameters to the script i get the following error, which tells me the usage for the script, even though I am passing the parameters as you can see in the code i am using.

Process completed successfully: true ExitCode: 2 StdOut: StdErr: usage:
temp_stream_with_init_oct10.py [-h] [--proto PROTO]
[--default_rpc_timeout_ms DEFAULT_RPC_TIMEOUT_MS]
[--print_raw_bytes] [--uart [UART]]
[--dummy] [--ble [BLE]]
[--connection_timeout [CONNECTION_TIMEOUT]]
[--ble_adv BLE_ADV [BLE_ADV ...]]
[--pair] [--duration_sec DURATION_SEC]
[--delay_sec DELAY_SEC] [--outward_leds]
[--inward_leds]
temp_stream_with_init_oct10.py: error: one of the arguments --uart --dummy --ble --ble_adv --pair is
required

The script takes 3 different parameters a boolean which is --inward_leds, an integer which is --delay_sec 1 and --ble Specs_xxxxx which is the ble's device name that it needs to connect to.

the following is my code.

B4X:
    shell.Initialize("shell", "/Users/username/.snaptools_virtualenvs/snaptools_0.0.21/bin/python", Array As String("temp_stream_with_init_oct10.py", "--ble Specs_45698c", "--delay_sec 1", "--inward_leds"))
shell.WorkingDirectory = "/Users/username/shells/protobv0.5"
shell.Run(-1)

I tried running the code with shell.InitializeDoNotHandleQuotes but i get the same results.

This sort of works as i mentioned but why doesn't it recognize the parameters i am passing?

Thanks,
Walter
 
Last edited:
Upvote 0
Top