Forum > General

[SOLVED] Accepting Input via PIPE but not via Keyboard

(1/1)

ASBzone:
Greetings,

I am developing a Windows console app that accepts parameters at the command-line, and I have added the following to enable it to grab information via PIPE as well.    (e.g. ECHO Some Stuff Here | myapp.exe )

The pipe part works fine using the following:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---while (not EOF) do begin  ReadLn(InputVar);  WriteLn('You entered: ', InputVar);end; 
However, if I run the command without having piped input, it waits for keyboard input.   What are my options for forcing STDIN to ignore the keyboard, so that it only tries to execute the ReadLn command if, in fact, data has been piped to the app?


I have seen threads such as below, which were helpful to me for getting the piping working at all.  But they don't address the other part of my issue.  ;D

https://forum.lazarus.freepascal.org/index.php?topic=16274.0
https://forum.lazarus.freepascal.org/index.php?topic=24663.0


Thanks

ASerge:

--- Quote from: ASBzone on July 18, 2018, 04:47:37 pm ---I am developing a Windows console app...
What are my options for forcing STDIN to ignore the keyboard, so that it only tries to execute the ReadLn command if, in fact, data has been piped to the app?

--- End quote ---

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$MODE OBJFPC}{$APPTYPE CONSOLE} uses Windows; function IsStdHandleRedirected(Handle: THandle): Boolean;var  Unused: DWORD;begin  Result := (GetFileType(Handle) <> FILE_TYPE_CHAR) or not GetConsoleMode(Handle, @Unused);end; begin  if IsStdHandleRedirected(StdInputHandle) then    Writeln('In pipe')  else    Writeln('OK')end.

ASBzone:
Awesome and exquisite.

Thanks, ASerge.  Works perfectly...

ASerge:
Advice for the future. If you later want to read the console output, even if you are redirected, you can do so by opening a file with a special name 'CONIN$'.

ASBzone:

--- Quote from: ASerge on July 18, 2018, 11:51:48 pm ---Advice for the future. If you later want to read the console output, even if you are redirected, you can do so by opening a file with a special name 'CONIN$'.

--- End quote ---

Advice accepted and stashed away safely. :D

Thanks again.

Navigation

[0] Message Index

Go to full version