2019年10月18日金曜日

開発環境

初めてのPerl 第7版 (Randal L. Schwartz(著)brian d foy(著)Tom Phoenix(著)近藤 嘉雪(翻訳)嶋田 健志(翻訳)オライリージャパン)の15章(プロセス管理)、15.9(練習問題)1の解答を求めてみる。

コード

#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use v5.18;
use Encode::Locale;
binmode STDIN, ':encoding(console_in)';
binmode STDOUT, ':encoding(console_out)';
binmode STDERR, ':encoding(console_out)';

say '1.';

chdir '/';
say 'system関数';
!system 'ls', '-l' or die 'something went wrong';
say 'exec関数';
exec 'ls', '-l' or die 'something went wrong';

# 実行されないことを確認
say 'hello';

入出力結果(Zsh、cmd.exe(コマンドプロンプト)、Terminal)

% ./sample1.pl 
1.
system関数
total 10
drwxrwxr-x+ 40 root  admin  1280 10 18 02:31 Applications
drwxr-xr-x  67 root  wheel  2144 10  9 01:31 Library
drwxr-xr-x@  8 root  wheel   256  9 30 05:23 System
drwxr-xr-x   5 root  admin   160  9 30 05:22 Users
drwxr-xr-x   4 root  wheel   128 10 18 18:02 Volumes
drwxr-xr-x@ 38 root  wheel  1216  9 30 05:28 bin
drwxr-xr-x   3 root  wheel    96 10  2 15:57 com.apple.TimeMachine.localsnapshots
drwxr-xr-x   2 root  wheel    64  8 25 07:24 cores
dr-xr-xr-x   3 root  wheel  4923 10  8 09:22 dev
lrwxr-xr-x@  1 root  admin    11 10  8 09:03 etc -> private/etc
lrwxr-xr-x   1 root  wheel    25 10  8 09:25 home -> /System/Volumes/Data/home
drwxr-xr-x   3 root  wheel    96 10  8 09:12 opt
drwxr-xr-x   6 root  wheel   192 10  8 09:09 private
drwxr-xr-x@ 64 root  wheel  2048 10  8 09:08 sbin
lrwxr-xr-x@  1 root  admin    11 10  8 09:08 tmp -> private/tmp
drwxr-xr-x@ 11 root  wheel   352 10  8 09:08 usr
lrwxr-xr-x@  1 root  admin    11 10  8 09:08 var -> private/var
exec関数
total 10
drwxrwxr-x+ 40 root  admin  1280 10 18 02:31 Applications
drwxr-xr-x  67 root  wheel  2144 10  9 01:31 Library
drwxr-xr-x@  8 root  wheel   256  9 30 05:23 System
drwxr-xr-x   5 root  admin   160  9 30 05:22 Users
drwxr-xr-x   4 root  wheel   128 10 18 18:02 Volumes
drwxr-xr-x@ 38 root  wheel  1216  9 30 05:28 bin
drwxr-xr-x   3 root  wheel    96 10  2 15:57 com.apple.TimeMachine.localsnapshots
drwxr-xr-x   2 root  wheel    64  8 25 07:24 cores
dr-xr-xr-x   3 root  wheel  4923 10  8 09:22 dev
lrwxr-xr-x@  1 root  admin    11 10  8 09:03 etc -> private/etc
lrwxr-xr-x   1 root  wheel    25 10  8 09:25 home -> /System/Volumes/Data/home
drwxr-xr-x   3 root  wheel    96 10  8 09:12 opt
drwxr-xr-x   6 root  wheel   192 10  8 09:09 private
drwxr-xr-x@ 64 root  wheel  2048 10  8 09:08 sbin
lrwxr-xr-x@  1 root  admin    11 10  8 09:08 tmp -> private/tmp
drwxr-xr-x@ 11 root  wheel   352 10  8 09:08 usr
lrwxr-xr-x@  1 root  admin    11 10  8 09:08 var -> private/var
$

0 コメント:

コメントを投稿