Intro to Programming ROBERT SEDGEWICK | KEVIN WAYNE
COMMAND-LINE INTERFACE
‣ brief overview ‣ live demo
http://introcs.cs.princeton.edu
Alan Kaplan and Kevin Wayne
Last updated on 2/21/17 9:31 AM COMMAND-LINE INTERFACE
‣ brief overview ‣ live demo
http://introcs.cs.princeton.edu Today’s plan: command-line interface
Brief overview. ・IDE vs. command line. ・Files and file systems.
Live demo. ・Navigating the file system. ・Java commands (including accessing stdlib.jar). ・Redirection and piping of standard input and output.
Note: you will need CLI for the Assignment 2.
3 Integrated development environment (IDE)
IDE. App designed for developing software.
“compile” button “run” button
pseudo-command line
4 Command-line interface
Command line. App where you type commands.
5 Convergence: Linux, OS X, and Windows
(September 1991)
6 Convergence: Linux, OS X, and Windows
(March 2001)
7 Convergence: Linux, OS X, and Windows
(August 2016)
8 Software for program development: tradeoffs
Command line advantages. ・More control over system. ・Approach works with any language. ・Easy to automate tasks via scripting.
IDE advantages. ・More intuitive for novices. ・Language-specific features.
This course. Use IDE to edit and compile; use command line to execute.
Beyond. Many other platforms embrace command line.
9 Files
File. Sequence of bits stored on a computer. Filename. String that uniquely identifies a file.
Mac OS X. /Users/wayne/cos126/hello/HelloWorld.java note: forward vs. backward slash Windows. C:\Users\wayne\cos126\hello\HelloWorld.java
10 File system hierarchy
Directory (folder). Collection of files and other folders.
root directory
/
Users Library Applications
wayne DrJava.app Firefox.app
Desktop cos126 Documents Music
hello loops Hello.mp4 Für Elise.mp4
readme.txt RandomWalker.class RandomWalker.java
/Users/wayne/cos126/loops/RandomWalker.java 11 COMMAND-LINE INTERFACE
‣ brief overview ‣ live demo
http://introcs.cs.princeton.edu Live demo of file system commands
13 Standard input and output abstractions
Command-line arguments. Provide arguments (strings) to a program.
Standard output stream. Abstraction for writing output (default = screen).
Standard input stream. Abstraction for reading input (default = keyboard).
standardstandardstandard input inputinput command-linecommand-linecommand-line argumentsargumentsarguments
standardstandardstandard output outputoutput
standard audio
standard drawing
AA bird’s-eyebird’s-eye viewview ofof aa JavaJava programprogram (revisited)(revisited) A Abird’s-eye bird’s-eye view view of ofa Javaa Java program program (revisited) (revisited) 14 Live demo of standard input and output commands
15 Navigating the file system
Action Mac OS X Terminal Windows Command Prompt
print current directory pwd cd
list contents of ls dir current directory
move down cd introcs one subdirectory
move up cd .. one subdirectory
move down cd introcs/hello cd introcs\hello multiple subdirectories
move to cd /Users/wayne cd \Users\wayne specified directory
copy, move, remove, make cp mv rm copy move del directory, remove directory mkdir rmdir mkdir rmdir
cycle through
autocomplete javac Hello
16 Java commands
Action Mac OS X Terminal Windows Command Prompt
compile Java program javac HelloWorld.java
execute Java program java HelloWorld
compile Java program javac-introcs HelloWorld.java (with our standard libraries)
execute Java program java-introcs HelloWorld (with our standard libraries)
file globbing javac *.java
Java compiler version javac -version
Java runtime version java -version
17 Command-line arguments, redirection, and piping
Action Mac OS X Terminal Windows Command Prompt
command-line arguments java Program arg1 arg2
redirect standard input java Program < input.txt
redirect standard input java Program > output.txt
piping java Program1 | java Program2
view contents, one more < input.txt screenful at a time java Program | more
java Program1 < input.txt | more combinations java Program < input.txt > output.txt java Program1 arg1 | java Program2 arg2
terminate program
signal end-of-file
18