cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-337927%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20Run%20Program()%20%E3%81%AB%E3%82%88%E3%82%8B%20Python%20%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%81%AE%E5%AE%9F%E8%A1%8C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-337927%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E3%81%93%E3%82%8C%E3%82%92%E5%AE%9F%E8%A1%8C%E3%81%99%E3%82%8B%E3%81%A8%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Efile_path%20%3D%20convertfilepath(%22%24temp%2Fx.bat%22%2C%22windows%22)%3B%0Asavetextfile(file_path%2C%20%22dir%5C!n%22)%3B%0A%0Arp%20%3D%20RunProgram(%20Executable(%20%22cmd.exe%22%20)%2C%0A%20Options(%20%7B%22%2FC%22%2C%20file_path%7D%20)%2C%0A%20ReadFunction(%22text%22)%20%2F%2F%20returns%20all%20text%20%0A%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%E3%83%90%E3%83%83%E3%83%88%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E5%AE%9F%E8%A1%8C%E3%81%AE%E4%BD%9C%E6%A5%AD%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%81%AF%E3%83%87%E3%82%B9%E3%82%AF%E3%83%88%E3%83%83%E3%83%97%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%81%AE%E3%82%88%E3%81%86%E3%81%A7%E3%81%99%E3%80%82%20Python%E3%81%AF%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%83%A9%E3%82%A4%E3%83%B3%E3%81%A7%E3%82%82%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E5%90%8D%E3%82%92%E8%A6%8B%E3%81%A4%E3%81%91%E3%82%8B%E3%81%9F%E3%82%81%E3%81%AB%E4%BD%9C%E6%A5%AD%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B%E3%81%A8%E6%80%9D%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%20%E7%B5%B6%E5%AF%BE%E3%83%91%E3%82%B9%E5%90%8D%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B%E3%81%AE%E3%81%8C%E8%89%AF%E3%81%84%E9%81%B8%E6%8A%9E%E3%81%A8%E6%80%9D%E3%82%8F%E3%82%8C%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fsuperuser.com%2Fquestions%2F396394%2Fhow-do-i-set-an-executables-working-directory-via-the-command-line-prior-to-ex%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fsuperuser.com%2Fquestions%2F396394%2Fhow-do-i-set-an-executables-working-directory-via-the-command-line-prior-to-ex%3C%2FA%3E%E8%B5%B7%E5%8B%95%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%A7%E4%BD%9C%E6%A5%AD%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%82%92%E6%8C%87%E5%AE%9A%E3%81%A7%E3%81%8D%E3%82%8B%E3%81%93%E3%81%A8%E3%82%92%E7%A4%BA%E5%94%86%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ESTART%20%2FD%20c%3A%5Ctemp%20notepad.exe%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-337888%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERun%20Program()%20%E3%81%AB%E3%82%88%E3%82%8B%20Python%20%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0%E3%81%AE%E5%AE%9F%E8%A1%8C%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-337888%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E7%A7%81%E3%81%8C%E8%A1%8C%E3%81%A3%E3%81%A6%E3%81%84%E3%82%8B%E3%83%8D%E3%82%B9%E3%83%88%E3%81%95%E3%82%8C%E3%81%9F%E5%91%BC%E3%81%B3%E5%87%BA%E3%81%97%E3%81%AB%E9%96%A2%E9%80%A3%E3%81%99%E3%82%8B%E5%95%8F%E9%A1%8C%E3%81%8C%E7%99%BA%E7%94%9F%E3%81%97%E3%81%A6%E3%81%84%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERunProgram()%20--%26gt%3B%20cmd%20--%26gt%3B%20Python%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%E6%AC%A1%E3%81%AE%E3%83%90%E3%83%83%E3%83%88%20%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AF%E5%AE%8C%E5%85%A8%E3%81%AB%E6%AD%A3%E5%B8%B8%E3%81%AB%E5%8B%95%E4%BD%9C%E3%81%97%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Eset%20JMP_PYTHON_PTH%3D%25UserProfile%25%5Cminiconda_JMP%5C%0A%0ACALL%20%25JMP_PYTHON_PTH%25%5CScripts%5Cactivate.bat%20%25JMP_PYTHON_PTH%25%0A%0Astart%20%2FB%20%2Fwait%20%22%22%20python%20test.py%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%E3%81%9D%E3%82%8C%E3%81%A7%E3%82%82%E3%80%81RunProgram()%20%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B%E5%A0%B4%E5%90%88%E3%80%81Python%20%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%20(test.py%20--%26gt%3B%20'C%3A%2Fa%2Fb%2Fc%2Ftest.py')%20%E3%81%AB%E7%B5%B6%E5%AF%BE%E3%83%91%E3%82%B9%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%97%E3%81%AA%E3%81%84%E9%99%90%E3%82%8A%E3%80%81%E3%82%B3%E3%83%BC%E3%83%89%E3%81%AF%E5%A4%B1%E6%95%97%E3%81%97%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EClearLog()%3B%0A%0Afile_path%20%3D%20ConvertFilePath(%20%22.%2Ftests%2Frun_python_installation_test.bat%22%2C%20windows)%3B%0A%0Arp%20%3D%20RunProgram(%20Executable(%20%22cmd.exe%22%20)%2C%0A%20Options(%20%7B%22%2FC%22%2C%20file_path%7D%20)%2C%0A%20ReadFunction(%22text%22)%20%2F%2F%20returns%20all%20text%20%0A%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%E7%B5%B6%E5%AF%BE%E3%83%91%E3%82%B9%E3%81%8C%E6%8C%87%E5%AE%9A%E3%81%95%E3%82%8C%E3%81%A6%E3%81%84%E3%81%AA%E3%81%84%E5%A0%B4%E5%90%88%E3%81%AB%E3%81%AE%E3%81%BF%E3%80%81%E6%AC%A1%E3%81%AE%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%8C%E7%99%BA%E7%94%9F%E3%81%97%E3%81%BE%E3%81%99%E3%80%82%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3E(base)%20C%3A%5CWINDOWS%5Csystem32%26gt%3Bstart%20%2FB%20%2Fwait%20%5C!%22%5C!%22%20python%20test.py%20%0Apython%3A%20can't%20open%20file%20'test.py'%3A%20%5BErrno%202%5D%20No%20such%20file%20or%20directory%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-337888%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3E%E8%87%AA%E5%8B%95%E5%8C%96%E3%81%A8%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88%E4%BD%9C%E6%88%90%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3E%E3%83%87%E3%83%BC%E3%82%BF%E3%82%A2%E3%82%AF%E3%82%BB%E3%82%B9%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3E%E5%93%81%E8%B3%AA%E3%81%8A%E3%82%88%E3%81%B3%E3%83%97%E3%83%AD%E3%82%BB%E3%82%B9%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E3%83%AA%E3%83%B3%E3%82%B0%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
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