zwora wrote:I was tyrying to use shell() function, but it does not work as I wish to.
Functions work as they are documented, not how you wish them to work.
If wishes were horses, beggars would ride
zwora wrote:shell("cd C:/Users/myusr/temp & python test.py")
gives … File not found
The documentation for the Shell function says:
Syntax: Shell (Pathname As String[, Windowstyle As Integer][, Param As String][, bSync])
Pathname: Complete path and program name of the program that you want to start
You did not provide the name of a program file. You provided a statement for cmd.exe. Of course the system cannot find the
file named "cd C:/Users/myusr/temp & python test.py".
If you need to change the directory before calling Python, the simple solution is to create, say with Notepad, a file which contains two lines, one to issue the
cd command and one to call your Python program. Then point the Shell function at the file you created.
Edit: 2022-03-21: Specifically, create Foo.cmd then use Basic statement: SHELL("C:\«YourPath»\Foo.cmd")
As I recall, when the file extension is .cmd, Windows knows that it's a cmd.exe batch file. |
Or, if you know where cmd.exe is located you might be able to pass a parameter to it with something like Shell("C:\Windows\System32\cmd.exe",6,"/c ""cd C:\Users\myusr\temp & python test.py""",TRUE). I may not have that syntax quite right since I haven't used damned Windows for over a decade. And C:\Windows\System32 might be the wrong path for
your system.
zwora wrote:obj = createUnoService("com.sun.star.system.SystemShellExecute")
obj.execute(python_path,path,0)
works unless I don't use imports from external libraries. But unfortunately I do, so I need to run python from my project directory.
I do not use Python, but surely the language provides a way for programs to control what libraries are available for imports. Learning how to do that would be a Python question, so if you want assistance with it I recommend that you consult a Python forum. This one supports OpenOffice and derivatives. I have no recommendations to you for a Python forum, but a web search will find one.
If this solved your problem please go to your first post use the Edit button and add [Solved] to the start of the subject field. Select the green checkmark icon at the same time.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7.6, iMac Intel. The locale for any menus or Calc formulas in my posts is English (USA).