Windows 10: Opening CMD from set location with arguments

Discus and support Opening CMD from set location with arguments in Windows 10 Software and Apps to solve the problem; 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... Discussion in 'Windows 10 Software and Apps' started by GXP10, Jul 20, 2016.

  1. GXP10 Win User

    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?

    :)
     
    GXP10, Jul 20, 2016
    #1

  2. Windows 10 Command Line Arguments

    Go to "Open Item Location" and then set it directly there from the folder. PS. this only works for regular programs. Apps from the app store don't have command line arguments.
     
    Shawn 'Cmdr' Keene [MVP], Jul 20, 2016
    #2
  3. DaveM121 Win User
    Running a command prompt as administrator ignores the "start in" folder

    Hi Rml123,

    There is another way to do this . . .

    Say if you want Command Prompt to open in C:\Windows from a shortcut on your Desktop

    Right click your Desktop, choose new - Shortcut, then set location to:

    cmd /K "cd C:\Windows\"

    You need to change this to match your required location
     
    DaveM121, Jul 20, 2016
    #3
  4. Kari Win User

    Opening CMD from set location with arguments

    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"[/quote]
    It should be just a path:
    Code: C:\Windows\System32\cmd.exe /k "C:\Users\lewis\Desktop\Main\Dir"[/quote]

    EDIT:

    No, that's not it! Was looking the error in wrong place.
     
  5. GXP10 Win User
    It should be just a path:
    Code: C:\Windows\System32\cmd.exe /k "C:\Users\lewis\Desktop\Main\Dir"[/quote] Kari[/quote] 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?
     
    GXP10, Jul 20, 2016
    #5
  6. Kari Win User
    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"[/quote]
     
  7. GXP10 Win User
    [/quote] Thanks, I fixed it *Smile
     
    GXP10, Apr 5, 2018
    #7
Thema:

Opening CMD from set location with arguments

Loading...
  1. Opening CMD from set location with arguments - Similar Threads - Opening CMD set

  2. Problems with cmd and setup location.

    in Windows 10 Gaming
    Problems with cmd and setup location.: When i try to install Python in windows 10, the file location keeps inmutable and i cant change it, also, if i try to install it into the default location what happens is that cmd doesn't detect it, i try to add the file path to the path in environment variables and i try to...
  3. Problems with cmd and setup location.

    in Windows 10 Software and Apps
    Problems with cmd and setup location.: When i try to install Python in windows 10, the file location keeps inmutable and i cant change it, also, if i try to install it into the default location what happens is that cmd doesn't detect it, i try to add the file path to the path in environment variables and i try to...
  4. Problems with cmd and setup location.

    in Windows 10 BSOD Crashes and Debugging
    Problems with cmd and setup location.: When i try to install Python in windows 10, the file location keeps inmutable and i cant change it, also, if i try to install it into the default location what happens is that cmd doesn't detect it, i try to add the file path to the path in environment variables and i try to...
  5. settings, cmd as administrator, powershell as administrator is not opening

    in Windows 10 Gaming
    settings, cmd as administrator, powershell as administrator is not opening: i can not open my settings app.also no option is showing to start cmd or powershell as administrator. https://answers.microsoft.com/en-us/windows/forum/all/settings-cmd-as-administrator-powershell-as/4e840f44-6303-46b7-a043-4c90e9e935c2
  6. settings, cmd as administrator, powershell as administrator is not opening

    in Windows 10 Software and Apps
    settings, cmd as administrator, powershell as administrator is not opening: i can not open my settings app.also no option is showing to start cmd or powershell as administrator. https://answers.microsoft.com/en-us/windows/forum/all/settings-cmd-as-administrator-powershell-as/4e840f44-6303-46b7-a043-4c90e9e935c2
  7. settings, cmd as administrator, powershell as administrator is not opening

    in Windows 10 Customization
    settings, cmd as administrator, powershell as administrator is not opening: i can not open my settings app.also no option is showing to start cmd or powershell as administrator. https://answers.microsoft.com/en-us/windows/forum/all/settings-cmd-as-administrator-powershell-as/4e840f44-6303-46b7-a043-4c90e9e935c2
  8. CMD not opening

    in Windows 10 Software and Apps
    CMD not opening: I am not able to open CMD, i have tried multiple fixes online but nothing really workedI am running on Windows 10 https://answers.microsoft.com/en-us/windows/forum/all/cmd-not-opening/fc3d4904-0d2d-4f26-8b4c-d66593d49207
  9. CMD not opening

    in Windows 10 BSOD Crashes and Debugging
    CMD not opening: I am not able to open CMD, i have tried multiple fixes online but nothing really workedI am running on Windows 10 https://answers.microsoft.com/en-us/windows/forum/all/cmd-not-opening/fc3d4904-0d2d-4f26-8b4c-d66593d49207
  10. CMD Popup (Arguments in the command line are invalid)

    in Windows 10 Support
    CMD Popup (Arguments in the command line are invalid): Hey guys Recently installed a new SSD into my laptop and fresh copy of Win 10 Enterprise I'm getting a random CMD popup every now and again, still trying to catch it with a screenshot next time I see it. But what I could manage to read while it briefly pops up is something...