How to open a file in a specified program using window comand prompt - windows

How can I open a file from the command prompt in a specified program rather than the default program for opening the file.
like in MAC terminal
open main.js -a "Sublime Text"
currently I only do
start filename.extension
which opens the file in the default program.
please what command can I use to achieve this?

With Windows, you type application first.
So with Notepad, which is on the Windows path, you can type
notepad filename.extension
By 'Windows Path' I mean a list of directories that Windows looks in for your application. If your app is in one of those folders, then you only have to type the application name. If your app isn't, then you need the full path to the application.
Most of the Windows native apps (like Notepad, MSPaint, etc) are automatically on the path. However apps that are installed afterwards sometimes don't update the path and you need the full path. You can usually get this by right-clicking on the application and getting properties. Often you'll need quote marks - specifically if there are spaces in the path, which there usually are because "Program Files", so:
"C:\Program Files (x86)\Notepad++\notepad++.exe" filename.extension
Note the quote marks go around the path to the application file itself - not all the way to the end of the line. An easy way to check that you've got the full path to the file is with the dir command:
dir "C:\Program Files (x86)\Notepad++\notepad++.exe"
Some applications expect instructions about what to do with the file, and you may need to figure out what else to put on the command line. Usually google will tell you this.
For example, to execute an SQL script, with one tool I use, just putting the filename on the command line won't work, you do something like:
"C:\Program Files\PostgreSQL\9.4\bin\psql.exe" -U user -d dbName -f filename.extension

Related

Executing a command-line .exe file

I have a .exe file converted from a .jar.
It is a command based application, so I have to start it with a batch script. Here is the batch script:
#echo off
cd C:\desktop\plant-text-adventure-win
start planttextadventure
pause
When I double click on the batch script, this happens: Windows could not find 'planttextadventure'. Please confirm if you have input the correct name and retry.
I don't know what is happening, I have no idea about cmd as I use Mac, but I can confirm I have an executable called planttextadventure.exe in a folder called plant-text-adventure-win.
You should test your batch file by executing it within a shell.
Simply enter within the start menu the command cmd to open up a shell. Within this black box you could now simply enter the commands from your batch script and lookout for some error message.
If you look at your script I would guess that the cd command (to change the current directory) is not correct. Maybe you should replace it with
cd %USERPROFILE%\Desktop\plant-text-adventure-win
because the desktop folder is on a default installation not directly under the root drive but within the user profile available.
Another solution to get this thing to work, is by opening the windows explorer, going to the .exe file you wish to execute and drag & drop the .exe file with a right mouse click onto the desktop.
Then a context menu appears and you select the option Create shortcut here.

How to run application from command prompt with arguments?

I have an application named DriveMaster which I want to run from command line with different arguments. The application is residing in:
"C:\Program Files (x86)\ULINK DM2012 PRO NET\v970\DriveMaster.exe\"
Now in Windows - Run, if I open command prompt and want to give a command like:
DriveMaster /s:Scriptname.srt
This should be able to launch DriveMaster with that particular script.
How can I do this? What should I need to add in the Environment variables so that I can run the application from command prompt?
In Windows 7:
In the menu Start click Computer
In the context menu, select System Properties
Select Advanced System Settings -> tab Advanced
Select Environment Variables Menu System Variables to find the PATH variable and click it.
In the editing window, change the PATH, adding value: ; C:\Program Files (x86)\ULINK DM2012 PRO NET\v970
Open Run and type: DriveMaster /s:Scriptname.srt
That's all.
When you're in the command prompt the working directory is given in the prompt:
C:\Users>
Here, I'm in the folder C:\Users. If I want to run a program or a script in the folder I'm currently in, I can use its name alone (e.g. DriveMaster). If the program is outside my working directory, I can't call it like that because there could be many DriveMasters in different folders throughout my computer. I can either change my directory to be the one that has this program, or I can specify where in the filesystem it's located.
Changing the directory and running:
C:\Users> cd "C:\Program Files (x86)\ULINK DM2012 PRO NET\v970\"
C:\Program Files (x86)\ULINK DM2012 PRO NET\v970> DriveMaster
Specifying the full path:
"C:\Program Files (x86)\ULINK DM2012 PRO NET\v970\DriveMaster"
(I need to use quotes here because the folder names have spaces and my command prompt may not know if it's part of the folder name or the beginning of another command or argument.)
On the same line I call the program, I can choose a number of arguments (also called options, switches, flags) to change the way to program behaves. If my program accepts another file and wants it in the form /s: and-then-the-filename, that file also needs to be in my working directory. If it lives somewhere else, I can use the full specification, like I've done above.
Environment variables are a little more complicated of a topic, but there is one we might be interested in here. The Path environment variable is a list of folders that the command prompt will look in when you try to use names of files that aren't in your working directory. If I know I'm going to be using this program frequently and like where it is, I can add its folder to my Path so that I can access it with just DriveMaster in the future:
set PATH=%PATH%;C:\Program Files (x86)\ULINK DM2012 PRO NET\v970
(If I mistype that command, though, I could break other things in a way that would be hard to fix.)
In a file name drivemaster.bat whch would be located at some point in the path,
#echo off
setlocal
"C:\Program Files (x86)\ULINK DM2012 PRO NET\v970\DriveMaster.exe" /s:Scriptname.srt
where Scriptname.srt would need to be quoted and supplied with a full pathname if it's not in the current directory.
Oh you want to type DriveMaster /s:Scriptname.srt
Then use
"C:\Program Files (x86)\ULINK DM2012 PRO NET\v970\DriveMaster.exe" %1
in that script in place of the original "c:..." line.
edit : removed stray terminal backslash from ...exe

Command-line equivalent of "start in" field on windows shortcuts

I'm in Windows 7. I have an executable. I put it somewhere. I put this location in my path. Now I can start it from anywhere using cmd. I have a different location where I work containing files the .exe will process. I shift right-click to open cmd in the work location. I can run the exe, but the exe starts in its own location and can't find the files. If I were to create a windows shortcut to it, I would get a "start in" field, which would work. But I do this a lot from many different locations and I don't want to create a shortcut in each location. How do I do this on the command line without creating a shortcut? It would be great if I could just run something like
progam /startin .
What is the actual syntax?
#echo off
setlocal
pushd "c:\where\you\want\to\start"
programname
popd
This is the basic structure.

Windows CMD: How to create symbolic link to executable file?

My goal is to add a few executables to my PATH (for example, chrome), so that I can call
> chrome
from the command prompt and it will launch Chrome.
I know I could add Chrome's containing directory to my path (set PATH=%PATH%<chrome_path_here>;), but since I have a few executables I want to add, I'd rather make a new bin directory that contains symbolic links to the actual executables and just add that single directory to my PATH.
The Chrome executable is located at
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
So I tried
> mklink chrome.exe "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
That successfully creates a symbolic link for the files (says so in output, and upon examining with > dir). I know my PATH is set up correctly, b/c when I run > where chrome it finds my new symbolic link.
However, when I try to execute chrome with my new link, nothing happens. A new empty window should appear, but nothing happens. No error message in the command prompt or anything.
What am I doing wrong? Am I misunderstanding symlinks in Windows? This is the approach I use in Linux all the time, but I'm new to Windows Cmd.
Thanks!
Most programs will not run from places other than they install location - which is exactly what happens when you try to run it from symlink.
It would be much easier to create CMD/BAT files in that folder with matching names which will launch programs from locations you want:
REM chrome.cmd
start /b cmd /c "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %*
With Windows 7 I confirm that symlinks do not work, are simply ignored as reported in the original question.
As Harry states in his comment, shortcuts do work, and to me are simpler and easier than writing a separate script for each new command I want to enable under CMD.
He states that you need to add .lnk to your PATHEXT variable in order to do this. I affirm that this does work, and with .lnk added to PATHEXT I can simply enter the name portion of the shortcut to run the command. For example if my shortcut is named "sublime.lnk" and PATHEXT includes .lnk, I can execute the link with the simple command "sublime". Nice!
As an alternative I found that PATHEXT need not be modified if I simply type in the full name of the shortcut, including the .lnk, at my CMD prompt. E.g., I created a shortcut named "sublime.lnk" under %HOMEPATH%/bin, pointing to "C:\Program Files\Sublime Text 2\sublime_text.exe".
Now by placing %HOMEPATH%\bin in my %PATH% I can run sublime via the command "sublime.lnk".
Either of the above are the best way I know of giving access to various commands from around Windows' filesystem from a CMD prompt. I'm not a Windows expert though, and welcome a better or more standardized solution to this problem.
P.S.: I just found out the hard way that you need to ensure the "Start in:" property of any shortcut you use in this fashion is blanked out, or your program will not start in the directory you invoke the shortcut from.
P.P.S.: On a related note, I discovered how to run Windows Explorer (or its replacement) on the directory your CMD session is logged in to: start ..

How do you add Start->Run shortcuts in Windows XP?

Does anyone know how you setup new commands to launch an application from the Start->Run box?
ie. you can type "firefox", "winword" or "excel" into the Run box and those applications will open even though they're not in the system path, but others won't. For example, with Firefox, there's no files named firefox.* in any of my system path directories:
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Subversion\bin;c:\Program Files\Microsoft
SQL Server\90\Tools\binn\
So there must be some way of linking applications with this path to create a shortcut command, maybe in the registry?
For example, I want to be able to launch Google Talk from the Run command, but typing the executable's name "googletalk.exe" doesn't do anything, which makes sense because it's not in the system path, but neither is firefox.exe, and typing "firefox" works.
Does anyone have any ideas?
From http://commandwindows.com/runline.htm:
Adding applications to the Path
Alternatively, the Registry can be
edited to explicitly contain the path
to the desired executable file or
files. The Registry key involved
isHKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App
Paths
Create a new sub-key with the name of the executable file that you
wish to add to the path. e .g.,
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App
Paths\somefile.exe
In this new key, add a string variable named "Path" containing the
value of the the path to your new
executable file, e.g., C:\Program
files\newprogramfolder\
The new key will already have an empty variable (Default). Edit it to
have the string value of entire
address of the new program executable , e.g., C:\Program files\newprogramfolder\somefile.exe
3 steps.
Create a shortcut to the foo.exe you want to run (foo.lnk)
Copy the foo.lnk to your C:\windows directory.
Run foo.exe by simply typing "foo" in your run dialog. ("start foo" in cmd prompt works too)
You could also use an application launcher like Launchy, Slickrun or Executor. That way you wouldn't have to mess with the registry. I use Executor and I can just select "send to -> executor" to create a shortcut for any app (or folder or whatever).
Run works with search paths, which include the Path environment variable and some others. There might be more information in the MSDN, give me a moment and I'll look it up.
I put a link to the application I want to launch in the "c:\windows" folder, and I use it all the time. You can also rename the link file, of course, to speed up things: for example, I type w, x or pp to launc Word, eXcel or PowerPoint.

Resources