Is there a example of getting stream into Console application in Xojo ?
And returning stream..
So basically I will be getting a stream, not a file path.
@Björn Eiacute;ksson I cannot get it to work at all on Windows (32 bit or 64 bit)
Generator.exe < Test.xml > Test.gen
stdin will always read zero string
Anyone know if this is bugged on Xojo for Windows ?
Of you do that you must use the args() parameter in the open event
Then if the console keeps running using a loop and doevents, you poll stdin.readall
Well this ended in Bug report, its all severely broken on Windows, StdIn does not work, and StdOut will write 80-90 kb at most out of 200kb file even if you flush and chunk it down.
54494 - StdIn and StdOut do not work correctly when redirected on Windows
OS: Windows 10
Xojo: Xojo 2018r4
Steps: StdIn and StdOut do not work correctly when redirected on Windows
If using syntax like this:
consoleApp < InputFile > outFile
Then StdIn will never get the InputFile as the StdIn
StdOut gets the Output file. But there is another bug there
If streaming say 200 kb file to the Stdout (to the outFile) then you will get 80-90 kb at most in the file even if your flushing and chunking it down in small pieces. If not chunking it then 40-50 kb is written at most.
StdIn and StdOut to work when redirected On Windows
Redirecting does not work at all on Windows and StdOut redirected wont write everything you send at it
@Björn Eiacute;ksson The Stdout is correctly re-directed to the file Test.gen
but the StdIn is not........
So your saying I cannot re-direct the StdIn and must take in the file name ??
When calling a Console Application you have parameters those you get as Args() As String in App.Open.
When you first open the console application in cmd or whatever; you do "Generator.exe <test.xml> test.gen"
App.Open, Args() As String:
Path to your exe is args(0)
<test.xml> = the first args(1)
test.gen = args(2)
and so on...
Then you must keep a main loop and use Stdin.ReadAll to read new (interactive) input
And use StdOut.Write to write back new output but the executable must keep running (using a loop and doevents)
App.Open(Args() As String):
// get the arguments/ note bad example but shows what it does.... // when MyExecutable.exe <test.xml> test.gen is called first. Dim path As String = Args(0) Dim xmlfilename As String = Args(1) // and so on... do // Keep running to read stdin from an interactive or async console/shell dim s as string = StdIn.ReadAll StdOut.Write Process( s ) App.DoEvents(10) loop until whateverYourExitFlags // Return code here: Return 0
This should not be a bug, the max length for stdin/stdout is a windows thing that should be settable somewhere.
I don't see how that makes sense
Since if called from other process then we wont have any file name
And in VisualStudio for example we can make utility that takes the syntax encode < fileA > fileB
And further more if the StdIn is empty then how would I read the file ? And how would I know when its done ? Utility like this normally after all ends when StdIn reaches EOF, not some random whateverYourExitFlag.
But StdIn is totally empty.
The test case is console:
encode < fileA > fileB
Real world case would be other application creating process and wiring up StdIn and Stdout with streams that are likely not filestreams.
(Like you can do with any other Console applications but apparently not Xojo)
A complete stream may be possible on some platforms but don’t expect all to work with long strings as stdout/stdin streams.
You may wanna keep the “console” application running and use it interactive, in a self-created loop calling App.DoEvents (since console apps in xojo have none) read the stdin.ReadAll untill StdIn.EOF (see above answers from Kem)
It should be possible to read files using the standartinpustream (stdin) since it’s in xojo’s docs here:
You may wanna try this using pipes.
Buffering of the “terminal” should be settable from the host (for example xojo’s shell class)
@Björn Eiacute;ksson There is no limit on StdOut in the Example above then Xojo is just chocking on NULL characters. Making streaming out not work for any binary files. If testing same with just "x" for every letter then it writes out 200 kb no problem.
Well xojo and NULL values don’t work well together.