質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Perl

Perlは多目的に使用される実用性が高い動的プログラミング言語のひとつです。

PowerShell

Windows PowerShellはコマンドラインインターフェースであり、システム管理を含むWindowsタスク自動化のためのスクリプト言語です。

Q&A

解決済

2回答

4981閲覧

perlのプログラムが動かない

peaceLB

総合スコア10

Perl

Perlは多目的に使用される実用性が高い動的プログラミング言語のひとつです。

PowerShell

Windows PowerShellはコマンドラインインターフェースであり、システム管理を含むWindowsタスク自動化のためのスクリプト言語です。

1グッド

0クリップ

投稿2019/06/10 04:43

編集2019/06/11 03:36

イメージ説明powershell画面### 前提・実現したいこと

windows powershellでperlのプログラムを動かしたいが、一行目で以下のエラーが出て上手く動作しません

発生している問題・エラーメッセージ

'.' は、内部コマンドまたは外部コマンド、 操作可能なプログラムまたはバッチ ファイルとして認識されていません。

該当のソースコード

perl PMiFish.pl 以下PMiFish.plコード #!/usr/bin/perl use strict; use warnings; system "perl ./Scripts/1_Preprocessing.pl"; 以下略 以下1_Preprocessing.plのコード #!/usr/bin/perl use strict; use warnings; #2018/12/04 1_2 Strip_primers change to use the Primer_Cleaner.pl #2018/07/01 1_2_Strip_primers.pl were changed to permit no primer seq #2018/01/29 change Blast to Usearch_global #2018/01/20 output a log file at 1_1 step #2018/01/05 add compress option #This script execute below scripts in each sample #1_1 Merge_paird_reads.pl #1_2_Strip_primers.pl #1_3_Quality_filter.pl #Setting my ($db, $primer, $diff, $separate, $depth, $size, $identity, $identity2, $dictionary, $family, $temporary, $compress, $trim); open (SET, "<", "Setting.txt") or die("error:$!"); while(<SET>){ if($_ =~ /^DB\s*=\s*(\S+)/){$db = $1;} elsif($_ =~ /^Primers\s*=\s*(\S+)/){my $temp = $1;if($temp =~ /^no$/i){$primer = "No";}else{$primer = $temp;}} elsif($_ =~ /^MaxDiff\s*=\s*(\S+)/){$diff = $1;} elsif($_ =~ /^Divide\s*=\s*(\S+)/){$separate = $1;} elsif($_ =~ /^Depth\s*=\s*(\S+)/){$depth = $1;} elsif($_ =~ /^Length\s*=\s*(\d+)/){$size = $1;} elsif($_ =~ /^UIdentity\s*=\s*(\S+)/){$identity = $1;} elsif($_ =~ /^LIdentity\s*=\s*(\S+)/){$identity2 = $1;} elsif($_ =~ /^Dictionary\s*=\s*(\S+)/){$dictionary = $1;} elsif($_ =~ /^Family\s*=\s*(\S+)/){$family = $1;} elsif($_ =~ /^Temporary\s*=\s*(\S+)/){$temporary = $1;} elsif($_ =~ /^Compress\s*=\s*(\S+)/){$compress = $1;} } close(SET); if($diff =~ /^length$/i){$trim = 1;} unless($diff =~ /\d+/){$diff = 2;} unless($separate){$separate = 0;} if($separate =~ /^yes$/i){$separate = 1;} else{$separate = 0;} unless($db){print "Error!! Check the DB name in Setting.txt.\n"; exit;} unless($primer){print "Error!! Check the Primer file name in Setting.txt.\n"; exit;} unless($depth){print "Error!! Check the number of Depth in Setting.txt.\n"; exit;} unless($size){print "Error!! Check the number of Length in Setting.txt.\n"; exit;} unless($identity){print "Error!! Check the upper cut line of Homology Search in Setting.txt.\n"; exit;} unless($identity2){print "Error!! Check the lower cut line of Homology Search in Setting.txt.\n"; exit;} unless($temporary){$temporary = "YES";} unless($compress){$compress = "YES";} unless(-f "./DataBase/$db"){print "No DataBase file or DataBase name didn't match in Setting.txt\n"; exit;} unless($primer =~ /^no$/i){ unless(-f "./DataBase/$primer"){print "No Primers file or file name didn't match in Setting.txt\n"; exit;} } unless(-f "./Dictionary/$dictionary"){ if($dictionary =~ /^no$/i){undef($dictionary);} else{print "The file of Dictionary for common name isn't or don't match the name in Setting.txt\n"; exit;} } unless(-f "./Dictionary/$family"){ if($family =~ /^no$/i){undef($family);} else{print "The file of Dictionary for Family name isn't or don't match the name in Setting.txt\n"; exit;} } #Get primer sequences my $countp = 0; my (%forward, %reverse, $namep); my ($primerF, $primerR); unless($primer =~ /^no$/i){ open (DATA2, "<", "./DataBase/$primer") or die("error:$!"); while(<DATA2>){ if($_ =~ /\#/){next;} chomp($_); if($_ =~ /Forward/){$countp = 1;next;} if($_ =~ /Reverse/){$countp = 2;next;} if($countp == 1){ if($_ =~ /^>(.+)/){$namep = $1;} elsif($_ =~ /^[a-z]/i){$_ =~ tr/[a-z]/[A-Z]/; $forward{$namep} = $_;} } if($countp == 2){ if($_ =~ /^>(.+)/){$namep = $1;} elsif($_ =~ /^[a-z]/i){ my $rev = reverse($_); $rev =~ tr/ATGCURYMKDHBV/TACGAYRKMHDVB/; $reverse{$namep} = $rev;} } } close(DATA2); unless(%forward){print "Error!! No primer seqeunce in $primer\n"; exit;} unless(%reverse){print "Error!! No primer seqeunce in $primer\n"; exit;} foreach(keys %forward){ unless($reverse{$_}){print "Error!! Paird primer need to be the same name!\nCheck $primer\n"; exit;} } foreach(keys %reverse){ unless($forward{$_}){print "Error!! Paird primer need to be the same name!\nCheck $primer\n"; exit;} } my $primer_num = keys %forward; if($primer_num == 1){$separate = 0;} if($trim and $primer_num == 1){ foreach(keys %forward){$primerF = length($forward{$_}); $primerR = length($reverse{$_});} }elsif($trim and $primer_num > 1){ print "Error! \"MaxDiff = length\" in Setting.txt can use when primer pair is one pair\n"; exit; } if($trim){$separate = 0;} } #Database and Usearch check opendir (DIR, "./DataBase") or die ("error:$!"); my @database = readdir DIR; my $dbcheck = 0; foreach(@database){ if ($_ =~ /${db}.udb/){$dbcheck++;} } closedir DIR; opendir (DIR, "./Tools") or die ("error:$!"); my @tool = readdir DIR; my $usearch; foreach (@tool) { if ($_ =~ /(usearch.+)/){$usearch = $1;} } closedir DIR; unless($usearch){print "Error!! Please put an usearch exectable file in Tools directory!\n"; exit;} unless($dbcheck){ my $command = "./Tools/$usearch -makeudb_usearch \"./DataBase/$db\" -output \"./DataBase/${db}.udb\""; system $command; } #Decompressing files opendir (DIR, "./Run") or die ("error:$!"); my @run = readdir DIR; my $gzip = 0; foreach (@run) { if ($_ =~ /.gz$/){$gzip++;} } closedir DIR; if($gzip){ print "Decompressing gz file to fastq file...\n"; foreach (@run) { if ($_ =~ /.gz$/){ my $comand = "gzip -d \"./Run/$_\""; system $comand; } } } #Get data names opendir (DIR, "./Run") or die ("error:$!"); my @read = readdir DIR; my $read_count = 0; my %file; foreach (@read) { if ($_ =~ /(.+)_R1/){$file{$1}++; $read_count++;} if ($_ =~ /(.+)_R2/){$file{$1}++; $read_count++;} } closedir DIR; unless(%file){print "None of fastq files in Run file!!\n"; exit;} foreach(keys %file){ if($file{$_} < 2){print "Error!! Check the Run directory!The analysis needs both R1 and R2 fastq files.\nR1 or R2 fastq files of $_ is not.\n"; exit;} } unless(-d "./Results"){mkdir "./Results";} print "============================================================\n"; print " 1_Preprocessing \n"; print "============================================================\n"; #assemble pair seqs mkdir "./Results/1_1_Merge_paird_reads"; unless($primer =~ /^no$/i){mkdir "./Results/1_2_Strip_primers";} mkdir "./Results/1_3_Quality_filter"; open (LOG, ">", "./Results/log.txt") or die("error:$!"); my (%log, %raw); my @youbi = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year += 1900; $mon += 1; if($min < 10){$min = "0$min";} print LOG "Start: $year/$mon/$mday ($youbi[$wday]) $hour:$min\n"; 以下略 ### 試したこと Active perlのインストールしなおし、環境変数の確認 ### 補足情報(FW/ツールのバージョンなど) ここにより詳細な情報を記載してください。
mitarai👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

mitarai

2019/06/10 05:22

そのエラーメッセージはPowerShellではなくCmdのものです。 Cmdで`. perl PMiFish.pl` としていませんか?
peaceLB

2019/06/10 05:32

ご返事ありがとうございます。 いいえ、これはpowershell上で行っていて エクスプローラーの動かしたいプログラムがある階層にてshift+右クリックで「powershellをここに開く」からpowershellを開き、コードを打ち込んでいます
mitarai

2019/06/10 05:40

そうでしたか。一応試しにその画面で`Get-ChildItem`を実行したらファイル一覧が表示されるでしょうか?
m.ts10806

2019/06/10 05:46

画面キャプチャご提示ください。 あとできればPMiFish.plのコードも。
peaceLB

2019/06/10 05:57

画像、コード追加しました Get-ChildItemを実行したところ、ファイルを認識しているようです
mitarai

2019/06/10 12:22

質問の編集ありがとうございます。間違いなくPowerShellから実行されてますね、失礼しました。perlのパスも通っているのでperlのスクリプトの方に問題がありそうですね。私はperlは門外漢なのでこれ以上は黙ります。(質問がマイナス評価されているようなので+1して中和しておきます。)
harrek

2019/06/11 20:58

1. このスクリプトをコマンドプロンプトから起動すると動作しますか? 2. このスクリプトはWindowsで動作させることを想定していますか?
guest

回答2

0

ベストアンサー

1_Preprocessing.pl の中でgzipコマンドを起動しているようですがgzipコマンドがインストールされていないのではないでしょうか?

投稿2019/06/11 21:14

harrek

総合スコア123

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

peaceLB

2019/06/12 03:00

必要なソフトが入っていなかったことが原因だったようで、エラーメッセージはでるもののきちんと動作してくれました。ありがとうございました。
guest

0

'.' は、内部コマンドまたは外部コマンド、
操作可能なプログラムまたはバッチ ファイルとして認識されていません。

Windowsでコマンドが見つからない場合のエラーメッセージですね。
system は OS上で コマンドを実行するので、その際に出力されてるような気がします。
(なんでエラーになるのかはわかりませんが・・・)

試しに system "perl ./Scripts/... のところの ./ を外してみたらどうなりますか?

perl

1 2system "perl Scripts/1_Preprocessing.pl"; 3system "perl Scripts/1_4_Rarefaction.pl"; 4system "perl Scripts/2_1_Find_unique.pl"; 5system "perl Scripts/2_2_Denoise.pl"; 6system "perl Scripts/2_3_Separate_chimera.pl"; 7system "perl Scripts/3_1_Usearch_global.pl"; 8system "perl Scripts/4_1_Annotation.pl"; 9system "perl Scripts/5_1_Fasta_for_Phylogenetic_Analysis.pl"; 10system "perl Scripts/5_2_Summary_table.pl"; 11system "perl Scripts/5_3_Fasta_classified_by_family.pl"; 12system "perl Scripts/6_1_Portal.pl"; 13system "perl Scripts/6_2_Phylogenetic_trees.pl"; 14

投稿2019/06/10 06:16

take88

総合スコア1379

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

peaceLB

2019/06/10 06:30

ご返信ありがとうございます。 試してみましたが、全く同じエラーをはいて駄目でした
take88

2019/06/10 06:36

そうですか。 `PMiFish.pl` ではなくて、 Scripts の下のファイルの問題のような気もします。 `system ...` の行を、1行だけ残して ほかはコメントアウトしてください。 そうして 実行してエラーが再現するのが どの箇所か特定させてみてもらえますか? 例えば、Scripts/1_Preprocessing.pl のところで再現するなら、Scripts/1_Preprocessing.pl の内容を 質問に追記してください。
archiver

2019/06/10 13:38

実際のActivePerlでの実装がどうなのかはわかりませんが、take88さんの指摘も踏まえると、system関数で起動しているシェルがcmd.exeになっていると思います。なので、perlスクリプトを指定しているパスの区切り文字を'/'から'\'に変えてみてください。 (多分、これでいける気が。状況は変わると思いますが)
peaceLB

2019/06/11 03:45

>take88さん 一行だけ残して実行してみましたが、やはり一行目に「'.' は、内部コマンドまたは外部コマンド、~」とエラーが出てしまいました。 1_preprocessing.plのコードの一部を追加しました(字数の関係で全部は入りきりません) >archiverさん パスの文字を変えてみましたが、 Unrecognized escape \S passed through at PMiFish4.pl line 5. と Can't open perl script "Scripts_Preprocessing.pl": Invalid argument のエラーがそれぞれ複数でて作動しませんでした
KojiDoi

2019/06/11 03:50

1_Preprocessing.plの202行目のコードを示してください。そこで変数が使われているなら、その変数の中身も示してください。
archiver

2019/06/11 04:53

>peaceLBさん 当初の状況からは進みましたね。 これでようやく、組まれたperlプログラムのデバッグになります。 >KojiDoiさん ここから先に出てくる問題は組まれたスクリプトの問題になり、当初の問題とは別になるので、別途質問を立てて進めた方がいいと思うのですがどうでしょう?
KojiDoi

2019/06/11 05:03

>archiverさん 1_Preprocessing.plのエラーメッセージこそが最初から出てきている問題点です。
peaceLB

2019/06/12 03:01

必要なソフトが入っていないことが原因だったようで、同じエラーメッセージはでますが動作してくれました。皆様ご対応ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問