- Thread Author
-
- #1
Hello, I am trying to open a file [FILE] with a program [PROGRAM]. I have a shortcut of those two on my desktop. When i drag and drop [FILE] on top of [PROGRAM], it works as expected, meaning that [FILE] gets openend correctly by using [PROGRAM] to open it (Similarly to how you would drop a ".txt" file on top of Notepad to edit it.) Now, when I tried in the terminal to write this start "[PROGRAM]" "[FILE]", the program gets opened as if I simply double clicked on it, meaning that [FILE] does not get opened with [PROGRAM].
What does dragging and dropping [FILE] on top of [PROGRAM] do more than the command I ran which makes it work? And how can I achieve the same result via command line?
EDIT: Creating a shortcut (.lnk file) on desktop to ""[PROGRAM]" "[FILE]"" works as I want it to.
EDIT2: I found a solution to my initial problem by doing something similar to my first edit, but if you know why the start "[PROGRAM]" "[FILE]" command didn't work, I would be very interested to know.
What does dragging and dropping [FILE] on top of [PROGRAM] do more than the command I ran which makes it work? And how can I achieve the same result via command line?
EDIT: Creating a shortcut (.lnk file) on desktop to ""[PROGRAM]" "[FILE]"" works as I want it to.
EDIT2: I found a solution to my initial problem by doing something similar to my first edit, but if you know why the start "[PROGRAM]" "[FILE]" command didn't work, I would be very interested to know.
Last edited:
Solution
Well thanks for your reply it made me look a little deeper into this. After some research, I found that I should have used start "" "[PROGRAM]" "[FILE]" as the first quote is used as the title of the new cmd window that will get opened. Also, I realized that I was using PowerShell (never used it before, so I supposed it was the same thing as cmd ) when I did my tests before I posted this thread, and I tried with cmd.exe and it worked flawlessly with the command start "" "[PROGRAM]" "[FILE]". Powershell gives me an error when I try the last command.
- Thread Author
-
- #3
Well thanks for your reply it made me look a little deeper into this. After some research, I found that I should have used start "" "[PROGRAM]" "[FILE]" as the first quote is used as the title of the new cmd window that will get opened. Also, I realized that I was using PowerShell (never used it before, so I supposed it was the same thing as cmd ) when I did my tests before I posted this thread, and I tried with cmd.exe and it worked flawlessly with the command start "" "[PROGRAM]" "[FILE]". Powershell gives me an error when I try the last command.
- Joined
- Mar 14, 2023
- Messages
- 99,932
Hi melbel — welcome back. Your shortcut/drag‑and‑drop behavior is normal; here’s why your commands behaved differently and how to do the same from both cmd.exe and PowerShell.
Why your first command failed
1) From cmd.exe
Why your first command failed
- In cmd.exe the built‑in start command treats the first quoted argument as the new console window’s title. So
start "Program" "C:\path\file.ext"
makes "Program" the window title and then starts "C:\path\file.ext" (which is treated differently). - The fix in cmd is to give an explicit (possibly empty) title, e.g. start "" "C:\path\program.exe" "C:\path\file.ext".
- In PowerShell start is an alias for Start-Process (not the cmd start), and it parses arguments differently — the same string form will not work there.
- Dropping a file onto a program or its shortcut launches that program with the file path passed as a command‑line argument (or invokes the program’s shell verb). So to replicate drag & drop you simply run the program with the file path as an argument.
1) From cmd.exe
- If program is on PATH:
notepad "C:\path\file.txt" - If program path contains spaces or you want to use start:
start "" "C:\Program Files\MyApp\app.exe" "C:\path\file.ext"
- Use Start-Process:
Start-Process -FilePath "C:\Program Files\MyApp\app.exe" -ArgumentList "C:\path\file.ext" - Or use the call operator (&) which behaves like running the exe directly:
& "C:\Program Files\MyApp\app.exe" "C:\path\file.ext" - To call the cmd start from PowerShell:
cmd.exe /c start "" "C:\Program Files\MyApp\app.exe" "C:\path\file.ext"
- Always quote paths that contain spaces.
- If you want the same behavior as dropping onto a shortcut that already has arguments in its Target, create a shortcut whose Target includes "%1" (or the file path) or run the program with the filename as an argument.
- Some programs use DDE or custom shell verbs; in those rare cases the shell may use a different mechanism than a simple command‑line argument, but for most programs the examples above reproduce drag‑and‑drop.
Similar threads
- Solved
- Replies
- 6
- Views
- 2K
- Solved
- Replies
- 1
- Views
- 3K