1
I would like to know how to pass parameters to an executable file on python
.
i have a python script that will call an executable and I need to pass two parameters to this executable.
I can call the executable with the os.system
or subprocess*
, what I’m not getting is to pass the parameters, for example with the subprocess_call
it calls the executable but waits to pass the parameters, despite passing the parameters in the syntax.
An example of what I’ve tried:
#!/usr/bin/python
import subprocess
subprocess.call(["dgTQ0126L028.exe","TQ0126L028.0000","/scratchout/teste_python"])
He even calls the executable dgTQ0126L028.exe
, but does not use the parameters I am passing TQ0126L028.0000
and /scratchout/teste_python
See if this helps https://docs.python.org/dev/library/argparse.html
– MarceloBoni
python
.exe
?– RFL
Indeed, you had not explained it correctly. I voted to reopen the question. Even so, I suggest you edit it and put the code you already have (because it will serve as a basis for someone to give you an answer). If possible make a [mcve] that illustrates your difficulty.
– Luiz Vieira
Read: http://answall.com/help/formatting
– Guilherme Nascimento
Are you sure it’s not a problem in the
dgTQ0126L028.exe
? (I voted to reopen)– Guilherme Nascimento
Hello, I believe that the problem is not in the executable, because the program calls exec. but keeps waiting for the parameters and when I manually pass the parameters it does correctly
– GustavoSM
What do you mean by "the program calls exec"? Which program, the such dbg*. exe? Did you put a print inside this program to verify that the parameters are actually being received? If you invoke via the command line, are the parameters processed? I agree with @Guilhermenascimento because the problem may not be in your Python code.
– Luiz Vieira
If you run on CMD like this
c:\pasta> dgTQ0126L028.exe TQ0126L028.0000 /scratchout/teste_python
what happens?– Guilherme Nascimento
When I run via command line the program runs correctly. I know it’s calling the executable when I use os.system and even subprocess.check_call, because it’s waiting for the two parameters that are needed ( TQ0126L028.0000 and /scratchout/teste_python). Calling the executable is when I invoke the executable.
– GustavoSM
correct is subprocess.check_call, test with another . exe, check these bars are not breaking the . exe
– Dorathoto
I ran a test here (I created a simple .exe in C# that prints what you get from the command line) and I couldn’t reproduce the problem with your exact code. I just don’t vote to close as "not reproduced" because I can’t anymore. If your executable "keeps waiting for the two parameters", it is almost certain that it is he who is doing something wrong. Maybe you should edit (or open a new question) focusing on the code of this executable, because your Python code is right.
– Luiz Vieira
Problem is exe and not user code
– Dorathoto
Then please do the following test: Fortran Program: program test implicit None Character(LEN=10):: gribfile, gribfile2 read(5,'(a)') gribfile read(5,'(a)') gribfile2 print*, "FILE", gribfile print*, "ARQUIVO2", gribfile2 end program test Program in Python: #! /usr/bin/python import subprocess subprocess.check_call(["test.exe","TQ0126L028","TQ0213L042",shell=True]) ####test.exe (executable from the Fortran program) ####TQ0126L028 (Parametro 1) #########TQ0213L042 (Parametro 2)
– GustavoSM