Coming from Perl environment, im trying to explore powershell and looking for a command similar to Perl Open() command,
please help
Coming from Perl environment, im trying to explore powershell and looking for a command similar to Perl Open() command,
please help
there is no direct equivalent but open() often used in cycles like
open($fh,'file.txt') while ( {$fh} ) { $_ }
and can be easily changed to pipelined equivalent
Get-Content 'file.txt' | Foreach-Object { $_ }
/I’m change angle to curly brackets/
i am streaming data from a linux server with something like below
########
open(OUT, “plink.exe -ssh -2 -t -l $user -pw $pass $host $cmd|”);
while () {
some parsing done here
}
if i do something like the above suggestion
& \tools\plink.exe $arg1 $arg2 $arg3 $arg4 $user $arg5 $pass $hostaddress $cmd | out-file .\tools\tmp.txt
get-content .\tools\tmp.txt -wait -tail 1 | foreach-object
{
write-host $_
}
.\tools\tmp.txt file size increases overtime and the ForEach-object seems to fail
can’t construct live example but may be something like
plink $arg1 $arg2 $arg3 $arg4 $user $arg5 $pass $hostaddress $cmd | foreach-object { Write-Host $_ }
can work ?
at least this test work
D:\> cat d:\cmd.ps1 1..10 | %{ $_ start-sleep -sec 1 } D:\> powershell -nologo -noprofile d:\cmd.ps1 | %{ write-host "Data; $_" } Data; 1 Data; 2 Data; 3 Data; 4 Data; 5 Data; 6 Data; 7 Data; 8 Data; 9 Data; 10