0

In order to solve this problem I have been trying to come up with different approaches.

I thought of using CON file for inter-process communication as follows:

REM The findstr is pretty much useless in this example!

set /P _MyVar=<CON & echo !_MyVar! | nc -w 1 -l -p 80 | findstr Host 1> CON

But no matter what I do I have always to type something into the console so that whole command is interpreted.

I believe this set /P _MyVar=<CON is blocking the process until something is provided to CON, therefore, the observed behaviour.

Is there any way to avoid this blocking behaviour so that the response from the netcat is tailored based on the request?

Community
  • 1
  • 1
utxeee
  • 953
  • 1
  • 12
  • 24
  • `con` doesn't "return" until it encounters a ctrl-z char. effectively you can NOT pipe input char-by-char using `con`, because only the entire input string will ever be returned, and only after the ctrl-z/eof char is encountered. – Marc B Oct 17 '16 at 19:58
  • Any idea for achieving the expected result? – utxeee Oct 17 '16 at 20:02
  • don't think there's any way of doing it from plain batch files. they're moronically stupid, to put it bluntly. there's hacks like using `choice` (see: http://stackoverflow.com/questions/13166100/how-can-i-return-a-single-character-from-the-console-in-a-batch-script-without-p), but that requires a loop, which means you can't keep a pipe open to `nc` – Marc B Oct 17 '16 at 20:04
  • I did not want to bring along any third-party component besides plain batch scripting and netcat executable but it is getting really difficult :) – utxeee Oct 17 '16 at 20:12
  • batch files are a prehistoric stoneage rock, literally. while you could try to do the programming equivalent of open heart surgery with it, the odds of patient survival are a wee bit on the low side. – Marc B Oct 17 '16 at 20:22
  • @MarcB Batch is a what you type to operate a computer. It's *moronically stupid* to treat it as a programming language. IBM engineers who wrote CMD added some programming features. But it's first and formost a way of telling a computer what to do without icons or mices. –  Oct 17 '16 at 22:26
  • `set /P` waits for _Return_... Anyway, please elaborate on what behaviour you expect: do you want just a single key-press to be waited for? or do you want to not wait for any key-presses at all? – aschipfl Oct 18 '16 at 10:09
  • I want to be able to custom-tailor the response of the netcat based on the request. I mean, the script should not wait for any input from the user because it will be provided automatically by the script. Well, at least, this is the behavior I am looking for but as far as I understood I cannot do that using plain batch files ! – utxeee Oct 18 '16 at 10:16

0 Answers0