Using Linux Remotely from Windows Electrical Engineering and Computer Science South Dakota State University Ken Gamradt This document will briefly describe the process of using Windows to edit programs and using Linux to compile and run programs. The examples shown in this document use Microsoft Windows 7 Enterprise and CentOS 6 Linux. In order to do this there are three basic software tools that will be needed: 1. A text editor that supports the Linux/Unix file system 2. A secure file transfer tool that allows the program file to be copied back and forth between Windows and Linux 3. A secure shell program that supports Linux command line access The text editor discussed in this document is Notepad++. Supports context sensitive syntax help for many programming languages. Supports Windows, Unix, Mac file systems. Installed on all lab computers in SDEH 131. The secure file transfer tool discussed in this document is Core FTP Lite Supports Secure File Transfer Protocol Installed on all lab computers in SDEH 131. WinSCP will also work. The secure shell program discussed in this document is Tera Term Pro Supports Secure Shell Protocol Installed on all lab computers in SDEH 131. PuTTY will also work. Download, install, and usage information for these tools can be found at: http://www.csc.sdstate.edu/~gamradtk/resources/downloads.html The basic process requires repeating the following sequence until the program runs correctly 1. Edit the program using Notepad++ 2. Transfer the program to Linux cscssh.sdstate.edu 3. Compiling the program from Linux 4. Running the program from Linux If the program does not compile or does not produce the desired results then return to step 1 and repeat the entire process until the program compiles and runs correctly. Linux Account Information and Linux Command Line Usage information can be found at: http://www.csc.sdstate.edu/~gamradtk/resources/linux.html
Step 1: Editing the program using Notepad++ The screen shot above shows an example of a simple C++ program. Notice that the program was saved using the name getvalue.cpp in the Temp directory located on the C: drive. You can see that Notepad++ provides context sensitive syntax help which makes writing syntactically correct programs easier to do.
In order to set the file system format open the following menu: Settings Preferences Select the New Document/Default Directory tab The default Format setting is Windows. For this discussion the Format has been changed because the file will eventually be transferred to Linux. This is absolutely crucial if Windows and Notepad++ are going to be used for creating text based data files. The file markers (end-of-line, end-of-file, etc ) are different in Windows and in Linux. Students often encounter problems running programs written in Windows that run in Linux because the file input commands cannot properly process the data file due to incorrect file markers.
Step 2: Transferring the program to Linux with Core FTP Lite The screen shot above shows Linux user gatesb connected to their Linux account located on the Computer Science Linux server named cscssh.sdstate.edu using Core FTP Lite. The window on the left shows the contents of the Temp directory located on the C: drive of the user s Windows computer. Notice that the program file that was created using Notepad++ is listed within the Temp directory as expected. The window on the right shows the user creating a new directory named Assignments in the user s home directory. Once the Assignments directory has been created simply double-click on it to make the Assignments directory the current Linux working directory. This will make it possible to transfer the user s program file directly into the new Assignments directory.
The screen shot above shows the program file named getvalue.cpp is selected for transfer to Linux. It also shows that the transfer mode is switched from Auto Mode to Ascii Mode for the transfer. This should be done for all text/character based files. The screen shot above shows the program file named getvalue.cpp is selected and about to be transferred or uploaded from the Temp directory in Windows to the Assignments directory in Linux.
The screen shot above shows the result of the transfer operation. There are now two copies of the program file. One copy in Windows and one copy in Linux.
Step 3: Compiling the program from Linux using Tera Term Pro Color coding: Blue: Directory Green: Executable File Black: Non-Executable File When user gatesb logs into their Linux user account their home directory becomes the current working directory. The directory listing command, ls, shows that the Assignments directory that was created using Core FTP Lite is located in the home directory. The changed directory command, cd, is used to make the Assignments directory the current working directory. The second use of the ls command shows that the program file named getvalue.cpp is located in the Assignments directory. This is where the program file was copied using Core FTP Lite. g++ o getvalue getvalue.cpp // alternative g++ getvalue.cpp g++ Tells Linux to use the GNU C++ compiler to compile the program (gcc C programs) o getvalue Tells Linux that if the program compiles then create an executable file named getvalue Does not have to match the program file, but this is a highly recommended practice a.out is the default executable file name created if the o switch is left off In this case no error or warning messages were generated. This means that the program is syntactically correct. This does not mean that the program is logically correct. In order to execute the program the executable file name is entered at the command line followed by pressing the Enter key.
The program: Cleared the output screen Displayed the program introduction which tells the user what the program is going to do Prompted the user for one integer value Displayed the entered value for the user If the program contained syntax and/or logical errors remember that the basic process is repeated until the program compiles and runs correctly. 1. Edit the program using Notepad++ 2. Transfer the program to Linux cscssh.sdstate.edu 3. Compiling the program from Linux 4. Running the program from Linux Do NOT skip any steps!!! When the program compiles and runs correctly use the exit command to disconnect from the remote system. The system( xxx ) function located in the cstdlib library is used to access the Linux command line from within a program. In this program system( clear ) was used to run the clear command from the command line from within the program. Linux does not support the Pause command that is sometimes used from Windows. These are two simple examples that illustrate that High Level programming languages are normally not 100% portable between operating systems.