I am trying to do simple piping with Scilab on Windows but it doesn't work neither in cmd.exe
nor in PowerShell.
I know I can pass commands to the interpreter as simple as echo %pi | scilex -nb -quit
, but I want to pass and read data instead of not directly sending commands.
I am using mgetl
with file descritor %io(1)
to access standard input, but the returned value is an empty matrix:
>echo Hello, World! | scilex -nb -quit -e "mgetl(%io(1))"
ans =
[]
If I use type
and a file, the same behavior happens. Here tmp
has a line break, but that is irrelevant because the behavior is the same with or without it:
>type tmp
Hello,
World!
>type tmp | scilex -nb -quit -e "mgetl(%io(1))"
ans =
[]
However, by removing the left-hand side of the pipe and keeping %io(1)
makes Scilab wait for user input until return then Ctrl+C is pressed:
>scilex -nb -quit -e "mgetl(%io(1))"
Hello, World!
ans =
"Hello, World!"
Using fd=mopen('tmp'); mgetl(fd), mclose(fd);
as the expression argument works, as expected, but that's not what I want, because it depends on a saved file.
I want to read data directly from the output of another process by using |
in cmd.exe
or PowerShell.
What is wrong with this approach? Is this an unexpected behavior?
It seems that you cannot read stdin with mgetl
, but with read
which uses Fortran formats, it works
C:\>echo Hello, World! | scilex -nb -e "read(%io(1),1,1,'(a)')"
ans =
"Hello, World! "
C:\>
The fact that mgetl cannot read from stdin is a bug that will be fixed in the upcoming release of Scilab (6.1.1) : http://codereview.scilab.org/#/c/21778, thanks for reporting.