How to create a Linux - like environment with Strawberry Perl and command prompt

I will show you how to create Linux -like environment with Strawberry Perl and a command prompt.

Perl engineers often work in a Linux/Unix environment when developing or operating a server.

If you want to test a program created for Linux on Windows, it will be easier if the command to be executed is as close as possible to Linux. ..

I will show you how to work at the command prompt in the same way as Linux.

You can work in the same way in Linux environment and command prompt

Is it possible to work in the same way in the Linux environment and the command prompt first? In January 2020, the following items were confirmed in the Windows 10 environment.

cd command

The Linux cd command also exists as a cd command at the command prompt.

File path delimiter is OK with "/"

The Windows file path delimiter is "\", but you can actually use "/". This is an example of using "/" in the cd command of the command prompt.

cd labo/perlzemi

gcc can be used if Strawberry Perl is installed

Use gcc, the C language compiler required to install Perl's XS module, from the beginning if Strawberry Perl is installed. I can.

gcc - help

Close command prompt

If you close the command prompt, the same command as the Linux exit command exists at the command prompt.

exit

Right - click to copy and paste

If you check the simple edit mode in the command prompt settings, you can copy and paste by right-clicking.

Easily copy and paste command prompt-right click

Continuous command execution by &&

You can use && at the command prompt as you would Linux.

command1 && command2

Redirects and pipes

Linux redirection and pipes are also available at the command prompt.

command> file.txt
command <file.txt
command1 | command2

Linux commands that do not exist at the command prompt

The following are Linux commands that do not exist at the command prompt. If it doesn't exist, let's create it.

If you have Strawberry Perl installed, the following path should be included in the command's search path:

C:\Strawberry\perl\site\bin

This is where the user-installed executables and batch files are stored.

Let's write a command that does not exist in this path.

Create ls command

Let's create a command that corresponds to the Linux ls command.

If you set the extension to ".bat", Windows will recognize it as a command.

Create a file called "ls.bat" in the search path of Strawberry Perl commands.

Write the following content. Now call the dir command with the ls command.

dir

You will be able to execute the following commands at the command prompt.

ls

Create make command

The command gmake can be used from the beginning if Strawberry Perl is installed.

So let's wrap this and create a make command.

Create a file called "make.bat" in the search path of Strawberry Perl commands.

Write the following content. Now the make command calls the gmake command.

gmake% 1

% 1 is a command line argument. If this is specified, arguments can be given to the make command, such as "make test".

You will be able to execute the following commands at the command prompt.

make

Other Linux commands

cat command or rm command etc. seems to be easy to make in the same way.

Try a Linux - like environment

Now let's do that for Linux. That is an example.

cd proj/MyModule
perl Makefile.PL
make && make test

Sounds good!

Frequently Asked Questions

Frequently asked questions.

Should I use an alias with DOSKEY?

Yes, I tried this. But when you run &&, the command prompt runs a new process. Actually, at this time, the environment is not inherited and the alias does not work.

Is powershell useless?

I feel that Powershell is designed to make Windows easier to operate, rather than improving the command prompt.

Redirects and pipes are connected to .net and the processed information is output.

If you want to check the operation of the program by using redirect or pipe, I feel that the command prompt, which outputs the information as it is, is excellent.

Related Informatrion