Archive forComputer Software

How To Run Shell Commands In Programmer’s Notepad

(c) 2008, Gary Fletcher

This tutorial shows you how to execute arbitrary MS-DOS commands from the Programmer’s Notepad text editor to process your text with an external tool. Programmer’s Notepad is a free, open-source text editor designed for software developers.

Using external programs from the editor you can include their output or use them to process the current file’s content. For example, you can check your HTML with a validation program. You can also use this feature to run custom scripts that retrieve data for a report.

The tutorial takes you through the simple steps required to set up a Programmer’s Notepad tool - a command executed from the editor - for shell commands. Each time the tool is run you are prompted to enter the shell command that you want to execute.

The example shows execution of the MS-DOS shell for convenience as it is found on any Windows PC. If you have alternative shells installed, e.g. with Cygwin, then you can create a similar tool by following the same procedure. Just replace the DOS “cmd” with the name of your preferred interpreter.

1. Create DOS Command Tool

Open the Programmer’s Notepad options window, click on Tools and then Options in the menu. In the Options window that opens click the Tools item in the list on the left of the screen.

Add Command Tool

Ensure that “(None – Global Tools);” is selected in the “Scheme:” field so that the tool is available for all types of file. Then click the “Add” button to create the tool, a New Tool Properties dialog opens.

In the New Tool Properties dialog give the tool a name, e.g. “DOS Command”. In the “Command:” field enter cmd. In the folder field enter %d. This instructs Programmer’s Notepad to start the cmd.exe program in the folder of the current file.

In the “Parameters:” field enter “/c %?” (no quotes). You can optionally assign a shortcut key by clicking in the “Shortcut:” field and pressing the key combination you want to assign.

You’ve now specified the program to execute for this tool. The next step is to tell Programmer’s Notepad to capture the output.

2. Capturing output into current file.

To capture the output of the command in the current file, go the the Console I/O tab of the New Tool Properties dialog. In this tab ensure that the “Capture output?” checkbox is checked and select “Replace my selection” from the drop down menu just below it.
Add Command Tool
Finally, press OK in the New Tool Properties dialog followed by OK in the Options window to complete tool creation.

3. Using The Tool

Now that you have created an MS-DOS command tool you can execute it from the editor. Select some text in the editor and use either the Tools menu or your chosen shortcut keys to start the tool.

Programmer’s Notepad prompts you to enter the command arguments. For this tool, simply enter the MS-DOS command that you want to execute, we’ll use “dir” as a an example as it’s sure to exist on all Windows PCs. Go ahead and enter the dir command in the prompt dialog then press enter.

Programmer’s Notepad runs the dir command and replaces your selection in the editor window with the listing of the current file’s directory.

Note that in versions of Programmer’s Notepad up to 2.0.7 the file contents are replaced if you don’t select text before running the tool. If this is not what you wanted, simply press the Ctrl-Z keys to undo the action and retrieve the previous file contents.

You can execute any DOS command, script or program that is in the working directory or on your path in exactly the same way. You can even pipeline several commands, just enter the pipe symbol in Tool parameters, e.g. “dir | grep foo”.

You now know how to create a flexible shell tool that you can use to run any command from Programmer’s Notepad. This is just one of the many useful features of Programmer’s Notepad that makes it a very powerful text editor for software developers. Why not give it a try at http://www.pnotepad.org

About The Author

Gary Fletcher writes articles for web sites, newsletters and blogs. Visit http://www.writescribe.com to learn more about buying articles for your site.

Use This Article On Your Site

You can use this article on your site if you wish. You must include the above About The Author section and copyright message. The hyperlink link must be active.

Comments

Programmer’s Notepad Review

Programmer’s Notepad is a free text editor with features designed for software developers. It offers a simple and intuitive GUI for working with popular programming languages and text formats. It is actively developed and supported and new features are released regularly. Read the complete article…

Comments