Sometimes you get spoiled by IDE's that have F5 to save and run what you have scripted so far... so... what can you do if you have 2 xterms (one for vi, the other for the output)?
perl -E 'while(-f $ARGV[0]){ $now=(stat(_))[9]; system($^X,@ARGV) if($ +now-$prev); $prev=$now; sleep 1}' /home/user/test.pl foo bar
with test.pl having:
#! env perl my $p1 = $ARGV[0]; my $p2 = $ARGV[1]; print "param1=$p1 param2=$p2\n";
yields:
param1=foo param2=bar
Tested to work under Win10 and Linux
Of course, there are better implementations. inotifywait or auditd if available on your system...
any perl golfers?
Update: we now incorporate the improvement made by haukex. Feel free to add more parameters if you need these
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: oneliner: autorun script when I save it in the editor
by haukex (Archbishop) on Mar 27, 2017 at 07:59 UTC | |
by FreeBeerReekingMonk (Deacon) on Mar 27, 2017 at 20:19 UTC | |
Re: oneliner: autorun script when I save it in the editor
by LanX (Saint) on Mar 26, 2017 at 23:29 UTC | |
by FreeBeerReekingMonk (Deacon) on Mar 27, 2017 at 20:16 UTC | |
by LanX (Saint) on Mar 27, 2017 at 21:34 UTC | |
by Anonymous Monk on Mar 28, 2017 at 14:25 UTC | |
Re: oneliner: autorun script when I save it in the editor
by reisinge (Hermit) on Mar 30, 2017 at 06:06 UTC | |
by FreeBeerReekingMonk (Deacon) on Apr 02, 2017 at 17:43 UTC |
Back to
Cool Uses for Perl