cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
FN
FN
Level VI

Executing Python programs with Run Program()

I am having an issue that should be related to the nested calls I am doing.

 

RunProgram() --> cmd --> Python

 

The following bat file works perfectly fine.

 

set JMP_PYTHON_PTH=%UserProfile%\miniconda_JMP\

CALL %JMP_PYTHON_PTH%\Scripts\activate.bat %JMP_PYTHON_PTH%

start /B /wait "" python test.py

 

 

And yet, when using RunProgram() the code fails unless I add the absolute path to the Python file (test.py --> 'C:/a/b/c/test.py')

 

ClearLog();

file_path = ConvertFilePath( "./tests/run_python_installation_test.bat", windows);

rp = RunProgram( Executable( "cmd.exe" ),
	Options( {"/C", file_path} ),
	ReadFunction("text") // returns all text	
	);

The error I get, again only if the absolute path is not given, is the following.

 

(base) C:\WINDOWS\system32>start /B /wait \!"\!" python test.py 
python: can't open file 'test.py': [Errno 2] No such file or directory

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: Executing Python programs with Run Program()

When I run this

file_path = convertfilepath("$temp/x.bat","windows");
savetextfile(file_path, "dir\!n");

rp = RunProgram( Executable( "cmd.exe" ),
	Options( {"/C", file_path} ),
	ReadFunction("text") // returns all text	
	);

it appears the working directory for the bat file execution is my desktop directory. I think python will use the working directory to find the filename on the command line too. Using the full path name seems a good choice.

 

https://superuser.com/questions/396394/how-do-i-set-an-executables-working-directory-via-the-command...  suggests you can specify the working directory in your start command:

START /D c:\temp notepad.exe

 

Craige

View solution in original post

1 REPLY 1
Craige_Hales
Super User

Re: Executing Python programs with Run Program()

When I run this

file_path = convertfilepath("$temp/x.bat","windows");
savetextfile(file_path, "dir\!n");

rp = RunProgram( Executable( "cmd.exe" ),
	Options( {"/C", file_path} ),
	ReadFunction("text") // returns all text	
	);

it appears the working directory for the bat file execution is my desktop directory. I think python will use the working directory to find the filename on the command line too. Using the full path name seems a good choice.

 

https://superuser.com/questions/396394/how-do-i-set-an-executables-working-directory-via-the-command...  suggests you can specify the working directory in your start command:

START /D c:\temp notepad.exe

 

Craige

Recommended Articles