Opening CMD from set location with arguments


  1. Posts : 13
    Windows 10
       #1

    Opening CMD from set location with arguments


    Hi, I have a folder full of files, and I'm looking for a way to automate the following:

    Through a shortcut or Batch file;
    Open the command prompt at a specific location, so the command prompt is ready to execute commands in that directory (the same as "Open Command Window here"), with arguments ready to execute when the file or shortcut opens. However I've ran into problems getting this to work. I have this in my shortcut:

    C:\Windows\System32\cmd.exe /k "cd C:\Users\lewis\Desktop\Main\Dir" C:\Python27\python.exe example.py -a ptc -u _____ -p _____ -l "__ __, _" -st 10"
    Note that the "_" are replaced with letters/numbers on my screen.

    In this case, the command prompt window opens, but I get a "The filename, directory name, or volume label syntax is incorrect." error.

    However if I do it this way, it works:
    Go to "C:\Users\lewis\Desktop\Main\Dir" --> Shift+Right-click --> "Open Command Window here" --> Paste in this Dir:
    C:\Python27\python.exe example.py -a ptc -u _____ -p _____ -l "__ __, _" -st 10"

    So, How can I get it to automate instead of me having to do it manually, and why does it function differently when I do it manually?
      My Computer


  2. Posts : 17,661
    Windows 10 Pro
       #2

    The /k switch for cmd.exe needs a path as a parameter, not a command.

    You have now a CD command as a parameter:
    Code:
    C:\Windows\System32\cmd.exe /k "cd C:\Users\lewis\Desktop\Main\Dir"

    It should be just a path:
    Code:
    C:\Windows\System32\cmd.exe /k "C:\Users\lewis\Desktop\Main\Dir"


    EDIT:

    No, that's not it! Was looking the error in wrong place.


    Kari
    Last edited by Kari; 21 Jul 2016 at 08:03.
      My Computer


  3. Posts : 13
    Windows 10
    Thread Starter
       #3

    Kari said:
    The /k switch for cmd.exe needs a path as a parameter, not a command.

    You have now a CD command as a parameter:
    Code:
    C:\Windows\System32\cmd.exe /k "cd C:\Users\lewis\Desktop\Main\Dir"
    It should be just a path:
    Code:
    C:\Windows\System32\cmd.exe /k "C:\Users\lewis\Desktop\Main\Dir"
    Kari
    I fixed it but I still get the same error. Could it be because I'm using "C:\Users\lewis\Desktop\Main\Dir" after already using a Directory?
      My Computer


  4. Posts : 17,661
    Windows 10 Pro
       #4

    The command to open Command Promp should be alone on its own command line. Try to separate them, put the Python command in next line in your batch file:

    Code:
    C:\Windows\System32\cmd.exe /k "cd C:\Users\lewis\Desktop\Main\Dir"
    C:\Python27\python.exe example.py -a ptc -u _____ -p _____ -l "__ __, _" -st 10"
      My Computer


  5. Posts : 13
    Windows 10
    Thread Starter
       #5

    Kari said:
    The command to open Command Promp should be alone on its own command line. Try to separate them, put the Python command in next line in your batch file:

    Code:
    C:\Windows\System32\cmd.exe /k "cd C:\Users\lewis\Desktop\Main\Dir"
    C:\Python27\python.exe example.py -a ptc -u _____ -p _____ -l "__ __, _" -st 10"
    Thanks, I fixed it :)
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 02:29.
Find Us




Windows 10 Forums