Console / stdin especially on windows
Posted: Tue Apr 23, 2024 12:41 am
I've been debugging an issue with communicating to stdin on windows for a few days now and would love some insight.
I was surprised to learn that the in-game console commands are available over stdin while running a headless server. I haven't really found much official documentation on it other than some mentions in the changelog.
On Linux everything seems to work without any fuss. I can start a headless server from the terminal and type in commands. I can automate it from every language I've tried.
On Windows using the same command to start a server:
when I try to type /h I get that '/h' is not recognized as an internal or external command, operable program or batch file.
However, when I run the node program:
I can type /h, /quit etc. into the console that I'm running the node program in and I'll get all the expected interactivity that I get on Linux.
Unfortunately, I can't seem to use node itself to write to Factorio's STDIN without it crashing. Adding the code below results in a crash
I have similar results when attempting in python.
According to some research the same seems to be true for C#.
However, I know FMTK successfully writes to Factorio's stdin using the same function calls that I tried in node. I've also heard of successes with Go and PowerShell.
So I guess I'd love some documentation on how Factorio opens it's STDIN on windows and ideally the conditions required to actually be able to communicate with it.
I was surprised to learn that the in-game console commands are available over stdin while running a headless server. I haven't really found much official documentation on it other than some mentions in the changelog.
On Linux everything seems to work without any fuss. I can start a headless server from the terminal and type in commands. I can automate it from every language I've tried.
On Windows using the same command to start a server:
Code: Select all
factorio.exe --start-server-load-latest
However, when I run the node program:
Code: Select all
exe_loc="C:\\Program Files\\Factorio\\bin\\x64\\factorio.exe"
args=["--start-server-load-scenario","base/freeplay"]
f = require('child_process').spawn(exe_loc,args)
f.stdout.pipe(process.stdout)
Unfortunately, I can't seem to use node itself to write to Factorio's STDIN without it crashing. Adding the code below results in a crash
Code: Select all
setTimeout(()=>{
f.stdin.write('/h')
},3000)
According to some research the same seems to be true for C#.
However, I know FMTK successfully writes to Factorio's stdin using the same function calls that I tried in node. I've also heard of successes with Go and PowerShell.
So I guess I'd love some documentation on how Factorio opens it's STDIN on windows and ideally the conditions required to actually be able to communicate with it.