35
Tool Development Chapter 08: Windows Command Prompt Nick Prühs

Tool Development 08 - Windows Command Prompt

Embed Size (px)

DESCRIPTION

Chapter 08 of the lecture Tool Development taught at SAE Institute Hamburg. Introduction to the windows command prompt, and command-line arguments and calling external programs in .NET.

Citation preview

Page 1: Tool Development 08 - Windows Command Prompt

Tool DevelopmentChapter 08: Windows Command Prompt

Nick Prühs

Page 2: Tool Development 08 - Windows Command Prompt

5 Minute Review Session

• What are the main advantages of design patterns?

• Which types of design patterns do you know?

• What’s the difference between inheritance and aggregation?

• Which types of polymorphism do you know?

• What’s the difference between cohesion and coupling?

• Which design patterns can be used for implementing an undo-redo stack?

• Which parties are typically involved in drag-and-drop operations?

• How do you tell the user about the effect that the drag-and-drop operation will have on the data?

2 / 58

Page 3: Tool Development 08 - Windows Command Prompt

Assignment Solution #7

DEMO

3 / 58

Page 4: Tool Development 08 - Windows Command Prompt

Objectives

• To understand how to interact with the Windows command prompt

• To learn how to create tool chains by creating new processes in .NET

4 / 58

Page 5: Tool Development 08 - Windows Command Prompt

Windows Commands

5 / 58

Command Description

Attrib Displays, sets, or removes attributes assigned to files or directories.

Cd Displays the name of or changes the current directory.

Cls Clears the Command Prompt window.

Copy Copies one or more files from one location to another.

Del Deletes one or more files.

Dir Displays a list of a directory's files and subdirectories.

Echo Displays messages or turns on or off the command echoing feature.

Md Creates a directory or subdirectory.

Move Moves one or more files from one directory to another directory.

Rd Deletes a directory.

Xcopy Copies files and directories, including subdirectories.

Page 6: Tool Development 08 - Windows Command Prompt

Attrib Command

Displays, sets, or removes attributes assigned to files or directories.

Syntax:

attrib [{+|-}r] [{+|-}h] [<Drive>:][<Path>][<FileName>] [/s [/d]]

6 / 58

Page 7: Tool Development 08 - Windows Command Prompt

Cd Command

Displays the name of or changes the current directory.

Syntax:

cd [<Drive>:][<Path>]cd [..]

7 / 58

Page 8: Tool Development 08 - Windows Command Prompt

Cls Command

Clears the Command Prompt window.

Syntax:

cls

8 / 58

Page 9: Tool Development 08 - Windows Command Prompt

Copy Command

Copies one or more files from one location to another.

Syntax:

copy [/y] <Source> [+<Source> [+ ...]] [<Destination>]

9 / 58

Page 10: Tool Development 08 - Windows Command Prompt

Del Command

Deletes one or more files.

Syntax:

del [/s] <Names>

10 / 58

Page 11: Tool Development 08 - Windows Command Prompt

Dir Command

Displays a list of a directory's files and subdirectories.

Syntax:

dir [<Drive>:][<Path>][<FileName>] [/p] [/a[[:]<Attributes>]] [/s]

11 / 58

Page 12: Tool Development 08 - Windows Command Prompt

Echo Command

Displays messages or turns on or off the command echoing feature.

Syntax:

echo [<Message>]echo [on | off]

12 / 58

Page 13: Tool Development 08 - Windows Command Prompt

Md Command

Creates a directory or subdirectory.

Syntax:

md [<Drive>:]<Path>

13 / 58

Page 14: Tool Development 08 - Windows Command Prompt

Move Command

Moves one or more files from one directory to another directory.

Syntax:

move [<Source>] [<Target>]

14 / 58

Page 15: Tool Development 08 - Windows Command Prompt

Rd Command

Deletes a directory.

Syntax:

rd [<Drive>:]<Path> [/s]

15 / 58

Page 16: Tool Development 08 - Windows Command Prompt

Xcopy Command

Copies files and directories, including subdirectories.

Syntax:

Xcopy <Source> <Destination> [/q] [/s] [/h]

16 / 58

Page 17: Tool Development 08 - Windows Command Prompt

Command Prompt Wildcards

Used to represent one or more characters when you are searching for files, folders, printers, computers, or people.

17 / 58

Wildcard character Description

Asterisk (*) Substitute for zero or more characters.

Question mark (?) Substitute for a single character in a name.

Page 18: Tool Development 08 - Windows Command Prompt

Windows Batch Files

• Unformatted text file that contains one or more commands and has a .bat file name extension.

• Allows you to simplify routine or repetitive tasks.

• When you type the file name at the command prompt, Cmd.exe runs the commands sequentially as they appear in the file.

18 / 58

Page 19: Tool Development 08 - Windows Command Prompt

Batch File Parameters

• Cmd.exe provides the batch parameter expansion variables %0 through %9.• %0 is replaced by the batch file name.

• %1 through %9 are replaced by the corresponding arguments that you type at the command line.

19 / 58

Page 20: Tool Development 08 - Windows Command Prompt

Command RedirectionOperators

20 / 58

Redirection operator Description

> Writes the command output to a file or a device, such as a printer, instead of the Command Prompt window.

< Reads the command input from a file, instead of reading input from the keyboard.

>> Appends the command output to the end of a file without deleting the information that is already in the file.

| Reads the output from one command and writes it to the input of another command. Also known as a pipe.

Page 21: Tool Development 08 - Windows Command Prompt

Batch File Commands

21 / 58

Command Description

If Performs conditional processing in batch programs.

Goto Within a batch program, redirects to a line identified by a label.

Rem Enables you to include comments (remarks) in a batch file or in your configuration files.

Page 22: Tool Development 08 - Windows Command Prompt

If Command

Performs conditional processing in batch programs.

Syntax:

if [not] errorlevel number command [else expression]

if [not] string1==string2 command [else expression]

if [not] exist FileName command [else expression]

22 / 58

Page 23: Tool Development 08 - Windows Command Prompt

Goto Command

Within a batch program, redirects to a line identified by a label.

Syntax:

goto label

:label

23 / 58

Page 24: Tool Development 08 - Windows Command Prompt

Rem Command

Enables you to include comments (remarks) in a batch file or in your configuration files.

Syntax:

rem [comment]

24 / 58

Page 25: Tool Development 08 - Windows Command Prompt

Command-Line Paramtersin .NETApplication Type Parameter Access

Console Application static void Main(string[] args)

WPF Application StartupEventArgs of the Startupevent handler

General Environment.GetCommandLineArgs();

25 / 58

Page 26: Tool Development 08 - Windows Command Prompt

Command-Line Paramtersin .NETC#

26 / 58

public static void Main(string[] args)

{

// Print all parameters to the console.

foreach (var arg in args)

{

Console.WriteLine(arg);

}

}

Page 27: Tool Development 08 - Windows Command Prompt

Starting Programs in .NET

• Process class is a useful tool for starting, stopping, controlling, and monitoring applications

• You can obtain a list of the processes that are running, or you can start a new process

• After a Process has been initialized, it can be used to obtain information about the running process• set of threads

• loaded modules (.dll and .exe files)

• amount of memory the process is using

27 / 58

Page 28: Tool Development 08 - Windows Command Prompt

Starting Programs in .NET

• The operating system persists the process handle, which is accessed through the Handle property of the Process component, even when the process has exited.

• Thus, you can get the process's administrative information, such as the ExitCode and the ExitTime.

28 / 58

Page 29: Tool Development 08 - Windows Command Prompt

Starting Programs in .NET

C#

29 / 58

// Create new process object.

Process process = new Process();

// Set target file and command-line arguments.

process.StartInfo.FileName = "ParameterDemo.exe";

process.StartInfo.Arguments = "/s";

// Start process.

process.Start();

Page 30: Tool Development 08 - Windows Command Prompt

Starting Programs in .NET

C#

30 / 58

// Create new process object.

Process process = new Process();

// Set target file. Windows will automatically open the file with the default program.

process.StartInfo.FileName = "textfile.txt";

// Start process.

process.Start();

Page 31: Tool Development 08 - Windows Command Prompt

Assignment #8

1. Title Bar – Map File Name

1. Keep the file stream of the current map file open untila new map is created or opened.

2. Update the title of the main window, always showingthe name of the current map file.

31 / 58

Page 32: Tool Development 08 - Windows Command Prompt

Assignment #8

2. Save to Current File

1. Add a Save menu item to the File menu of the Main Window, and change the Save As toolbar button to a Save toolbar button.

2. Executing the Save command should write the currentmap data to the current map file, if any, and open theSave As dialog otherwise.

32 / 58

Page 33: Tool Development 08 - Windows Command Prompt

Assignment #8

3. Title Bar – Modified Asterisk

Update the title of the main window, showing an asteriskafter the current map file name while the map is dirty.

33 / 58

Page 34: Tool Development 08 - Windows Command Prompt

References

• Microsoft. Command-Line Reference. http://technet.microsoft.com/en-us/library/cc754340.aspx, August 15, 2012.

• Microsoft. Using batch files. http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx, May 2015.

• Microsoft. Using wildcard characters. http://technet.microsoft.com/en-us/library/bb490639.aspx, May 2015.

34 / 58

Page 35: Tool Development 08 - Windows Command Prompt

Thank you for your attention!

Contact

Mail

[email protected]

Blog

http://www.npruehs.de

Twitter

@npruehs

Github

https://github.com/npruehs

35 / 58