-1

Is there a way to create a command in Windows 7 command line to open some text file in selected text editor? E.g. pspad "text file location" that will open text file in PSPad.

Art Gertner
  • 7,149
  • 11
  • 42
  • 72
user46581
  • 107
  • 3
  • 2
    What do you mean by "create a command"? Do you mean creating a script that runs your command `pspad "textfile"`for you or do you mean making the command line open a file with the default text editor? Or a script that asks you what editor you want to use with the specified file? Describe what you want to happen when you run your "command". – Jonah Jul 23 '14 at 11:28
  • I'm sorry I don't know the right syntax. I mean to create a variable that I write in CMD line and the result is opening text file with some preselected text editor (`pspad "txt location"`). Also I wouldn't have to write the editor location every time. – user46581 Jul 23 '14 at 11:35
  • if you can post the full path to your pspad.exe and a text file you want to open, I could try to provide an example for you (if this helps). Also, see my answer below – Art Gertner Jul 23 '14 at 11:39
  • You could put the line ` "text.txt">` in a batch file in your user folder to make it so that you can type `opentxt` and it will run opentxt.bat and run the long command for you. – Jonah Jul 23 '14 at 11:51

2 Answers2

0

Not sure if I understood the question correctly, but if I did, then you have just answered your own question with this line:

E.g. pspad "text file location" that will open text file in PSPad

That is exactly what you need. Most programs that are designed to open the files of some format take the URL of the file as the CMD argument. So supplying the path to the file after the name of the program will do exactly what you want.

Few things to consider:

  • Make sure that the location of the executable is known to the system. It has to be in $PATH variable. Otherwise you will need to specify a full path to executable
  • You can use absolute or relative path to text file, but if you are using relative path, then be aware of your current working directory

Here is the syntax for running PSPad from cmd:

"drive:\path\PSPad.EXE" [/switch -switch] "file1" ["file2" ...]

This example show the use of absolute path to executable. If you don't want to use full path to executable then add it to your $PATH variable. If you are unfamiliar with the environment variables, then here is a very comprehensive guide.

You can read more about command line parameters for PSPad here

Art Gertner
  • 7,149
  • 11
  • 42
  • 72
  • Thanks for answers, best solution for me was to replace %windir% notepad with PSPad notepad.exe. Then just `notepad txt-file` :) – user46581 Jul 25 '14 at 08:33
0

If your textfiles (*.txt) already are associated with pspad, you can use the following command to do just that:

start mytext.txt

The command start will start a program with optional parameters. If you ask to launch a file, it will instead open that file by the associated program in windows. If you use start followed by a path (directory) with no file, the default for showing paths will be used to show you that path. By default that is explorer. So start . will open the current folder in explorer.

LPChip
  • 59,229
  • 10
  • 98
  • 140