doulian7252 2013-04-03 03:28
浏览 42
已采纳

在Go中运行os / exec命令后获取环境

I am running an external command via os.exec package. I can specify an environment for the external command using the Cmd.Env member. However, the command may modify that environment and I want to capture those modifications for subsequent invocations of the command.

How do I find out the state of the environment immediately after the command terminates?

  • 写回答

1条回答 默认 最新

  • duanlei2150 2013-04-03 04:08
    关注

    I don't believe there is a standard interface to do what you're after in a platform independent way.

    On systems like Linux for instance, the process's environment is managed through the environ global variable in the process's address space. Changes to the local environment only propagate to new processes because this environment is passed to the execve system call.

    So to do what you want, you really need the cooperation of the process you are executing. Perhaps you could have it write out its environment in response to a signal?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记