1. Joined : May 2015
    Posts : 13
    Windows 10
       21 Jul 2016 #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 System SpecsSystem Spec


  2. Joined : Oct 2013
    A Finnish ex-pat in Germany
    Posts : 9,520
    Windows 10 Pro
       21 Jul 2016 #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 System SpecsSystem Spec


  3. Joined : May 2015
    Posts : 13
    Windows 10
       21 Jul 2016 #3

    Kari said: View Post
    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 System SpecsSystem Spec


  4. Joined : Oct 2013
    A Finnish ex-pat in Germany
    Posts : 9,520
    Windows 10 Pro
       21 Jul 2016 #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 System SpecsSystem Spec


  5. Joined : May 2015
    Posts : 13
    Windows 10
       21 Jul 2016 #5

    Kari said: View Post
    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 System SpecsSystem Spec


 


Similar Threads
Thread Forum
Solved Task Scheduler Error: One or more specified arguments not valid
What is wrong with Task Scheduler on Windows 10? Here is where I add my task: 53088 53089 53090
General Support
Solved Documents Location Changed But Property Location Is Correct - ???
Greetings! I tried to search for posts on my issue but all that comes up is advice on how to move your Documents folder. I already did that. I changed my location from my SSD C:\ drive to my data drive E:\. Everything seemed fine until today when I...
General Support
Solved Windows Defender Task Scheduler Action Arguments
I've seen 2 ways to add the full scan argument to MpCmdRun.exe. The first is "-Scan -ScanType 2" (without the quotes). The second is "-Scan -ScheduleJob -ScanType 2" (without the quotes). I can't seem to find anything on the -ScheduleJob...
AntiVirus, Firewalls and System Security
Windows Arguments List - Start Programs Minimized with Task Scheduler.
Hello Community! I'm trying to get BBC iPlayer downloads to start automagically at 2100 so that it can start downloading Doctor Who. I'd like it to start minimized, but I am unsure how to do so. In addition to this, does anyone know if there...
Performance & Maintenance
Choose a default location when opening File Explorer
Hello, Is it possible to choose a default location/folder to open when opening File Explorer from the task bar? Default is that it opens Quick access. I use OneDrive a lot, and would really like to see that I could set that to open that location....
Software and Apps
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 19:10.
Find Us
Twitter Facebook Google+



Windows 10 Forums