1

I have seen this thread (and many others) but I am still not able to retrieve the args in python.

1) With this...

Run Cmd \k "Python  C:\my.py %myvar%"

... a Cmd is open but nothing happens : my.py isn't started.

2) With this...

Run C:\my1.py %myvar% 

... the python script is run but when I retrieve the args with sys.argv, I only get the path of the script not myvar. Len(sys.arg) return 1 so myvar isn't passed down to python.

stevecody
  • 658
  • 1
  • 6
  • 18
MagTun
  • 5,619
  • 5
  • 63
  • 104
  • `sys.argv[0] will be your script path, your argument should be from sys.argv[1] ` – Pyd Dec 25 '17 at 14:22
  • `sys.argv[1]` is %myvar% provided that there aren't spaces – Jean-François Fabre Dec 25 '17 at 14:23
  • @pyd @ Jean-François Fabre, thanks for that and sorry for not being more precise. `len(sys.arg)` returns 1, I don't have a `sys.argv[1]`. – MagTun Dec 25 '17 at 14:26
  • seems that your association with .py files is broken (registry issue). You should repair your python installation. see this: https://stackoverflow.com/questions/39434689/need-ot-use-a-batch-file-or-power-shell-to-set-a-file-extension-to-a-program – Jean-François Fabre Dec 25 '17 at 14:29
  • @Jean-FrançoisFabre, sys.arg works when I start my python script directly in CMD with the args with `python C:\myscript.py sometext`. – MagTun Dec 25 '17 at 14:47

1 Answers1

1

This thread solved it.

commands=
(join&
 python "C:\my.py" "%myvar%"`n
)
Run, cmd /c %commands%  
return

It's also possible to use Run, cmd /k %commands% or Run,%comspec% /k %commands%

MagTun
  • 5,619
  • 5
  • 63
  • 104