Linux下的.net应用问题,无法通过Shell脚本运行 [英] Problem with .net app under linux, doesn't work from shell script
问题描述
我正在处理.net后提交钩子,以通过其Soap SDK将数据输入OnTime.我的钩子可以在Windows上正常工作,但是在我们的生产RHEL4颠覆服务器上,当从shell脚本调用时,它将不起作用.
I'm working on a .net post-commit hook to feed data into OnTime via their Soap SDK. My hook works on Windows fine, but on our production RHEL4 subversion server, it won't work when called from a shell script.
#!/bin/sh
/usr/bin/mono $1/hooks/post-commit.exe "$@"
当我使用命令行中的参数执行它时,它可以正常工作.通过shell脚本执行时,出现以下错误:(看来我用来获取修订日志数据的SVN的流程执行存在一些问题):
When I execute it with parameters from the command line, it works properly. When executed via the shell script, I get the following error: (looks like there is some problem with the process execution of SVN that I use to get the log data for the revision):
Unhandled Exception: System.InvalidOperationException: The process must exit before getting the requested information.
at System.Diagnostics.Process.get_ExitCode () [0x0003f] in /tmp/monobuild/build/BUILD/mono-1.9.1/mcs/class/System/System.Diagnostics/Process.cs:149
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_ExitCode ()
at SVNLib.SVN.Execute (System.String sCMD, System.String sParams, System.String sComment, System.String sUserPwd, SVNLib.SVNCallback callback) [0x00000]
at SVNLib.SVN.Log (System.String sUrl, Int32 nRevLow, Int32 nRevHigh, SVNLib.SVNCallback callback) [0x00000]
at SVNLib.SVN.LogAsString (System.String sUrl, Int32 nRevLow, Int32 nRevHigh) [0x00000]
at SVNCommit2OnTime.Program.Main (System.String[] args) [0x00000]
我尝试使用mkbundle
和mkbundle2
制作一个可以命名为post-commit
的独立显示器,但出现了另一条错误消息:
I've tried using mkbundle
and mkbundle2
to make a stand alone that could be named post-commit
, but I get a different error message:
Unhandled Exception: System.ArgumentNullException: Argument cannot be null.
Parameter name: Value cannot be null.
at System.Guid.CheckNull (System.Object o) [0x00000]
at System.Guid..ctor (System.String g) [0x00000]
at SVNCommit2OnTime.Program.Main (System.String[] args) [0x00000]
有什么想法为什么它可能会因Shell脚本而失败或捆绑版本可能有什么问题?
Any ideas why it might be failing from a shell script or what might be wrong with the bundled version?
@Herms, I've already tried it with an echo, and it looks right. As for the $1/hooks/post-commit.exe
, I've tried the script with and without a full path to the .net assembly with the same results.
@Leon, I've tried both $1 $2
and "$@"
with the same results. It is a subversion post commit hook, and it takes two parameters, so those need to be passed along to the .net assembly. The "$@"
was what was recommended at the mono site for calling a .net assembly from a shell script. The shell script is executing the .net assembly and with the correct parameters, but it is throwing an exception that does not get thrown when run directly from the command line.
@Luke, I tired it, but that makes no difference either. I first noticed the problem when testing from TortoiseSVN on my machine (when it runs as a sub-process of the subversion daemon), but also found that I get the same results when executing the script from the hooks directory (i.e. ./post-commit REPOS REV
, where post-commit
is the above sh script. Doing mono post-commit.exe REPOS REV
works fine. The main problem is that to execute, I need to have something of the name post-commit
so that it will be called. But it does not work from a shell script, and as noted above, the mkbundle
is not working with a different problem.
推荐答案
正常情况下,某些进程在关闭其stdout后会挂一会儿是正常的(即,您从文件中读取了文件结尾).您需要在读取所有数据之后但在检查ExitCode之前调用proc.WaitForExit()
.
It is normal for some processes to hang around for a while after they close their stdout (ie. you get an end-of-file reading from them). You need to call proc.WaitForExit()
after reading all the data but before checking ExitCode.
这篇关于Linux下的.net应用问题,无法通过Shell脚本运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!