I have a WORKING batch file that I want to execute by my Python program. here is the portion of program related to that task:
def execute_batch_file(self):
batch_file_path = r'C:\Users\UTENTE\Desktop\Programmi compilati Python\OP10\prova.bat'
subprocess.Popen(batch_file_path, shell=True)
when I run the program I get the error message "Cannot open exaple.prn for reading". Again, if I execute the batch file manually I have no issue whatsoever. It does work fine. When I run it by my program I get the message above. For info, the batch file lunches an "lpr" command for a ".prn" file to be printed.
Any clue about the issue?
Thanks alot.
"%~dp0exaple.prn"
instead of justexaple.prn
would have solved the problem too.%~dp0
is drive and path of argument 0 which is the batch file name argument string.%~dp0
expands therefore to full directory path of the batch file always ending with a backslash which is concatenated with the file name expected in the batch file directory and not in the current working directory.