Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirecting stderr of SC2 process #101

Closed
inoryy opened this issue Oct 21, 2017 · 5 comments
Closed

Redirecting stderr of SC2 process #101

inoryy opened this issue Oct 21, 2017 · 5 comments

Comments

@inoryy
Copy link
Contributor

inoryy commented Oct 21, 2017

Currently there's no way to redirect SC2 proc stderr (i.e. Game has started. messages) except for doing it globally, which is quite annoying if you're running multiple SC2 env instances.

The way it should be done from within Python is by allowing stderr=... parameter in the subprocess.Popen call during StarcraftProcess::_launch call.
One way to set is could be a global flag since project relies on gflags already.

@tewalds
Copy link
Member

tewalds commented Nov 16, 2017

Do I understand this as a request to be able to redirect the stderr from the game to a file, and to do so via a global flag? How would that help when you're running multiple instances? Wouldn't it send the stderr from all instances to that same file?

@world2vec
Copy link

Yes, it is really annoying.
For me , I just want to hide all output from SC2 proc and keep output of my program.
Do not how to do this!!!

@inoryy
Copy link
Contributor Author

inoryy commented Feb 12, 2018

I'll look into fixing this in the near future, but a simple workaround I've been using so far is to redirect all stderr somewhere, i.e. python main.py 2> logs/errors.log

@Joy1112
Copy link

Joy1112 commented Apr 19, 2023

Unfortunately, this behavior is still the same in today's version.

I suggest updating the method StarcraftProcess()._launch() that already receives **kwargs but does not make use of it.

    def _launch(self, run_config, args, **kwargs):
        """Launch the process and return the process object."""
        # del kwargs
        try:
            with sw("popen"):
                return subprocess.Popen(args, cwd=run_config.cwd, env=run_config.env, **kwargs)
        except OSError:
            logging.exception("Failed to launch")
            raise SC2LaunchError("Failed to launch: %s" % args)

In this way, one could send something like stderr=subprocess.PIPE to ridirect the output of stderr when calling the function LocalBase().start(), e.g.,

from pysc2 import run_configs

my_run_config = run_configs.get(version=<some_game_version>)
# just drop stderr in this example
sc2_proc = my_run_config.start(want_rgb=False, stderr=subprocess.DEVNULL)

@tewalds
Copy link
Member

tewalds commented Apr 19, 2023

Hah, I happened to be pulling in PRs for the first time in ages, and saw this comment. Thanks for the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants