linux下的.net应用程序有问题,不是吗';无法从shell脚本工作

linux下的.net应用程序有问题,不是吗';无法从shell脚本工作,.net,linux,svn,mono,.net,Linux,Svn,Mono,我正在开发一个.net post提交钩子,通过他们的Soap SDK将数据提供给OnTime。我的钩子在Windows上运行良好,但在我们的RHEL4 subversion服务器上,当从shell脚本调用时,它将无法工作 #!/bin/sh /usr/bin/mono $1/hooks/post-commit.exe "$@" 你知道为什么shell脚本会失败,或者捆绑版本有什么问题吗 编辑:,我已经用echo试过了,看起来不错。至于$1/hooks/post commit.exe,我已经尝试了

我正在开发一个.net post提交钩子,通过他们的Soap SDK将数据提供给OnTime。我的钩子在Windows上运行良好,但在我们的RHEL4 subversion服务器上,当从shell脚本调用时,它将无法工作

#!/bin/sh /usr/bin/mono $1/hooks/post-commit.exe "$@" 你知道为什么shell脚本会失败,或者捆绑版本有什么问题吗

编辑:,我已经用echo试过了,看起来不错。至于
$1/hooks/post commit.exe
,我已经尝试了该脚本,该脚本带有或没有指向.net程序集的完整路径,结果相同

编辑:,我尝试了
$1$2
“$@”
,结果相同。它是一个subversion提交后钩子,需要两个参数,因此需要将这些参数传递给.net程序集。mono站点建议使用
“$@”
从shell脚本调用.net程序集。shell脚本正在使用正确的参数执行.net程序集,但它引发的异常在直接从命令行运行时不会引发

编辑:,除了
BASH\u LINENO
BASH\u SOURCE


编辑:,我累了,但那也没什么区别。我第一次注意到这个问题是在我的机器上测试TortoiseSVN时(当它作为subversion守护进程的子进程运行时),但我也发现从hooks目录执行脚本时得到了相同的结果(即
/post-commit REPOS REV
,其中
post-commit
是上面的sh脚本。执行
mono-post-commit.exe REPOS REV
可以很好地工作。主要问题是要执行,我需要有一个名为
post-commit
的东西,以便调用它。但它不能从shell脚本工作,如上所述,
mkbundle
没有处理其他问题。

只是一个可能有助于调试的随机想法。请尝试将shell脚本更改为:

#!/bin/sh
echo /usr/bin/mono $1/hooks/post-commit.exe "$@"
检查并查看它打印的行是否与您希望它运行的命令相匹配。可能您在shell脚本中处理的命令行参数没有达到您希望的效果


我不知道您对脚本的输入是什么,但是路径前的$1对我来说有点不合适。

您确定要这样做吗

/usr/bin/mono $1/hooks/post-commit.exe "$@"

$@扩展到所有参数。$@“扩展到通过空格连接的所有参数。我怀疑您的shell脚本不正确。您没有确切说明希望脚本执行的操作,因此这限制了我们提出建议的可能性。

比较shell中的环境变量和脚本中的环境变量。

尝试放置“cd$1/hooks/”在运行mono的行之前。在shell中,当您从该文件夹运行mono时,可能会在该文件夹中找到一些程序集,但在运行脚本时却找不到这些程序集。

在从命令行验证代码是否正常工作后,我发现它不再工作了!我查看了.net代码以查看是否有任何程序集事情有道理

以下是我所拥有的:

static public int Execute(string sCMD, string sParams, string sComment, string sUserPwd, SVNCallback callback) { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.UseShellExecute = false; proc.StartInfo.Verb = "open"; proc.StartInfo.FileName = "svn"; proc.StartInfo.Arguments = Cmd(sCMD, sParams, sComment, UserPass()); proc.Start(); int nLine = 0; string sLine = ""; while ((sLine = proc.StandardOutput.ReadLine()) != null) { ++nLine; if (callback != null) { callback.Invoke(nLine, sLine); } } int errorCode = proc.ExitCode; proc.Close(); return errorCode; } 静态公共int执行(字符串sCMD、字符串sparam、字符串sComment、, 字符串sUserPwd,SVNCallback回调) { System.Diagnostics.Process proc=新的System.Diagnostics.Process(); proc.EnableRaisingEvents=false; proc.StartInfo.RedirectStandardOutput=true; proc.StartInfo.CreateNoWindow=true; proc.StartInfo.UseShellExecute=false; proc.StartInfo.Verb=“打开”; proc.StartInfo.FileName=“svn”; proc.StartInfo.Arguments=Cmd(sCMD、sParams、sComment、UserPass()); proc.Start(); int-nLine=0; 字符串sLine=“”; 而((sLine=proc.StandardOutput.ReadLine())!=null) { ++在线; if(回调!=null) { callback.Invoke(nLine,sLine); } } int errorCode=proc.ExitCode; 过程关闭(); 返回错误码; } 我改变了这一点:

while (!proc.HasExited) { sLine = proc.StandardOutput.ReadLine(); if (sLine != null) { ++nLine; if (callback != null) { callback.Invoke(nLine, sLine); } } } int errorCode = proc.ExitCode; 当(!进程已退出) { sLine=proc.StandardOutput.ReadLine(); if(sLine!=null) { ++在线; if(回调!=null) { callback.Invoke(nLine,sLine); } } } int errorCode=proc.ExitCode;
看起来进程的挂起时间比我得到输出的时间长了一点,因此
proc.ExitCode
抛出了一个错误。

一些进程在关闭stdout后挂起一段时间是正常的(即,从它们那里读取完文件)。您需要调用
proc.WaitForExit()
读取所有数据后但检查ExitCode之前

static public int Execute(string sCMD, string sParams, string sComment, string sUserPwd, SVNCallback callback) { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.UseShellExecute = false; proc.StartInfo.Verb = "open"; proc.StartInfo.FileName = "svn"; proc.StartInfo.Arguments = Cmd(sCMD, sParams, sComment, UserPass()); proc.Start(); int nLine = 0; string sLine = ""; while ((sLine = proc.StandardOutput.ReadLine()) != null) { ++nLine; if (callback != null) { callback.Invoke(nLine, sLine); } } int errorCode = proc.ExitCode; proc.Close(); return errorCode; } while (!proc.HasExited) { sLine = proc.StandardOutput.ReadLine(); if (sLine != null) { ++nLine; if (callback != null) { callback.Invoke(nLine, sLine); } } } int errorCode = proc.ExitCode;