[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[系统相关] CMD窗口启动和批处理文件中启动的程序运行环境有不同?

最近在弄一个新研发平台的分布式编译,使用mips-gcc交叉编译,在winxp,win2003和win7上使用cygwin。

分布式编译使用的是distcc,版本为distcc-2.18.3 (for cygwin)。

distcc分布式编译简单介绍一下:
该分布式编译使用的方式是client+server的方式,编译时client可以同时向多个server发送编译请求,server在本机编译完成后,将obj文件回传给client。
client运行distcc.exe,server运行distccd.exe(监听3632端口)。client编译前需要指定server的ip,通过设置环境变量DIST_HOSTS告诉distcc。

distcc.exe distccd.exe 都位于cygwin安装目录bin目录下。

我写了一个bat文件,放到“C:\Documents and Settings\All Users\「开始」菜单\程序\启动”目录下,以便研发人员每次开机的时候可以自动运行distccd.exe服务程序。
现在的问题是:
开机后,distccd能正常启动,但是接收到client发送过来的编译请求时,找不到编译器mips-elf-gcc.exe,而该编译器位于cygwin安装目录的crosscompiler\bin目录下;
但是如果在cmd.exe窗口里输入如下两句启动的distccd,却一切正常,
>set PATH=C:\cygwin\crosscompiler\bin;C:\cygwin\bin;%PATH%

>distccd --daemon --allow 192.168.1.0/24

还请各位大侠帮忙看看问题出在哪里?
  1. @echo off
  2. ::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  3. :: 检测系统中是否有distccd在运行
  4. ::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  5. set /a DistccdCount=0
  6. for /f "delims=" %%i in ('tasklist ^| findstr /i "distccd.exe"') do (set /a DistccdCount+=1)
  7. if not %DistccdCount%==0 (echo distccd is already running && goto eof)
  8. :: 先终止当前的distccd线程
  9. ::taskkill /F /IM distccd.exe
  10. ::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  11. :: 根据操作系统类型,查询注册表,寻找cygwin安装目录
  12. ::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  13. set TheOs=
  14. if /i not "%os%."=="Windows_NT." goto UnknownSystemError
  15. :: 判断系统版本
  16. for /f "delims=" %%i in ('ver ^| findstr /i "6.1"') do (set TheOs=Win7 && goto Win7)
  17. for /f "delims=" %%i in ('ver ^| findstr /i "6.1"') do (set TheOs=WinVista && goto WinVista)
  18. for /f "delims=" %%i in ('ver ^| findstr /i "5.0"') do (set TheOs=Win2000 && goto Win2000)
  19. for /f "delims=" %%i in ('ver ^| findstr /i "5.1"') do (set TheOs=WinXP && goto WinXP)
  20. for /f "delims=" %%i in ('ver ^| findstr /i "5.2"') do (set TheOs=Win2003 && goto Win2003)
  21. :: 默认是XP
  22. set TheOs=WinXP && goto WinXP
  23. :Win7
  24. :WinVista
  25. echo Find Cygwin install path @%TheOs%
  26. for /f "skip=2 tokens=1-3" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Cygnus Solutions\Cygwin\mounts v2\/" /v native') do (
  27.   set "CYGWIN_HOME=%%c"
  28. )
  29. if "%CYGWIN_HOME%"=="" (goto UnknowCygwinInstallPath) else (goto FindDistccd)
  30. :Win2000
  31. :WinXP
  32. echo Find Cygwin install path @%TheOs%
  33. for /f "skip=4 tokens=1-3" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/" /v native') do (
  34.   set "CYGWIN_HOME=%%c"
  35. )
  36. if "%CYGWIN_HOME%"=="" (goto UnknowCygwinInstallPath) else (goto FindDistccd)
  37. :Win2003
  38. echo Find Cygwin install path @%TheOs%
  39. for /f "skip=1 tokens=1-3" %%a in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Cygnus Solutions\Cygwin\mounts v2\/" /v native') do (
  40.   set "CYGWIN_HOME=%%c"
  41. )
  42. if "%CYGWIN_HOME%"=="" (goto UnknowCygwinInstallPath) else (goto FindDistccd)
  43. ::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  44. :: 启动distccd
  45. ::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  46. :FindDistccd
  47. echo cygwin install path is: %CYGWIN_HOME%
  48. :: 默认distccd位于cygwin安装目录bin下
  49. set DISTCCD_PATH=%CYGWIN_HOME%\bin
  50. :: 检测distccd是否存在
  51. if not exist %DISTCCD_PATH%\distccd.exe (goto NoDistccd)
  52. :: 环境变量中加入distccd以及cygwin的bin目录
  53. set PATH=%CYGWIN_HOME%\usr\bin;%CYGWIN_HOME%\bin;%PATH%
  54. :: 启动distccd
  55. :: 这里有个没有解决的问题,在cmd窗口中,只要设置正确的PATH,可以直接输入distccd命令启动,但是在bat文件中却有问题
  56. :: 通过bash虽然能启动distccd,但是distccd必须放到cygwin安装目录的bin下。具体原因未知
  57. echo start distccd...
  58. :: 增加mips-elf-gcc.exe的目录,希望distccd执行的时候能找到该编译器
  59. set PATH=%CYGWIN_HOME%\crosscompiler\bin;%PATH%
  60. ::%DISTCCD_PATH%\distccd.exe --daemon --allow 192.168.1.0/24 --verbose --log-file 1.txt --pid-file 1.pid
  61. ::bash --noprofile -c "distccd --daemon --allow 192.168.1.0/24 --verbose --log-file 1.txt --pid-file 1.pid"
  62. bash --noprofile -c "distccd --daemon --allow 192.168.1.0/24"
  63. if errorlevel 0 (goto Success) else (goto Error)
  64. ::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  65. :: 以下为各种错误处理
  66. ::+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  67. :UnknownSystemError
  68. echo Unknown OS!!!
  69. goto Error
  70. :UnknowCygwinInstallPath
  71. echo Cannot find cygwin install path!!!
  72. goto Error
  73. :NoDistccd
  74. echo Cannot find distccd @%DISTCCD_PATH%
  75. goto Error
  76. :Success
  77. echo distccd start successful...
  78. :: 显示三秒后,直接退出,sleep是cygwin的bin下的工具
  79. sleep 3
  80. goto eof
  81. :Error
  82. echo distccd start failed...
  83. pause
  84. goto eof
  85. :eof
复制代码

补充一下,现在出问题的机器操作系统都是 WinXP SP3

TOP

大虾快来看看啊!

TOP

返回列表