<p>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.</p>

<pre>
#!/bin/sh
/usr/bin/mono $1/hooks/post-commit.exe "$@"
</pre>

<p>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):</p>

<pre>

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]
</pre>

<p>I've tried using <code>mkbundle</code> and <code>mkbundle2</code> to make a stand alone that could be named <code>post-commit</code>, but I get a different error message:</p>

<pre>
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]
</pre>

<p>Any ideas why it might be failing from a shell script or what might be wrong with the bundled version?</p>

<p><b>Edit:</b> <a href="https://stackoverflow.com/questions/54503/problem-with-net-app-under-linux-doesnt-work-from-shell-script#54537">@Herms</a>, I've already tried it with an echo, and it looks right. As for the <code>$1/hooks/post-commit.exe</code>, I've tried the script with and without a full path to the .net assembly with the same results.</p>

<p><b>Edit:</b> <a href="https://stackoverflow.com/questions/54503/problem-with-net-app-under-linux-doesnt-work-from-shell-script#54545">@Leon</a>, I've tried both <code>$1 $2</code> and <code>"$@"</code> 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 <code>"$@"</code> was what was recommended at the mono site for calling a .net assembly from a shell script. The shell script <i>is</i> 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.</p>

<p><b>Edit:</b> <a href="https://stackoverflow.com/questions/54503/problem-with-net-app-under-linux-doesnt-work-from-shell-script#54568">@Vinko</a>, I don't see any differences in the environment other than things like <code>BASH_LINENO</code> and <code>BASH_SOURCE</code></p>

<p><b>Edit:</b> <a href="https://stackoverflow.com/questions/54503/problem-with-net-app-under-linux-doesnt-work-from-shell-script#54818">@Luke</a>, 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. <code>./post-commit REPOS REV</code>, where <code>post-commit</code> is the above sh script. Doing <code>mono post-commit.exe REPOS REV</code> works fine. The main problem is that to execute, I need to have something of the name <code>post-commit</code> so that it will be called. But it does not work from a shell script, and as noted above, the <code>mkbundle</code> is not working with a different problem.</p>

[{'answer_id': 54537, 'author': 'Herms', 'author_id': 1409, 'author_profile': 'https://Stackoverflow.com/users/1409', 'pm_score': 0, 'selected': False, 'text': '<p>Just a random thought that might help with debugging.  Try changing your shell script to:</p>\n\n<pre><code>#!/bin/sh\necho /usr/bin/mono $1/hooks/post-commit.exe "$@"\n</code></pre>\n\n<p>Check and see if the line it prints matches the command you\'re expecting it to run.  It\'s possible your command line argument handling in the shell script isn\'t doing what you want it to do.</p>\n\n<p>I don\'t know what your input to the script is expected to be, but the $1 before the path looks a bit out of place to me.</p>\n'}, {'answer_id': 54545, 'author': 'Leon Timmermans', 'author_id': 4727, 'author_profile': 'https://Stackoverflow.com/users/4727', 'pm_score': 0, 'selected': False, 'text': '<p>Are you sure you want to do</p>\n\n<pre><code>/usr/bin/mono $1/hooks/post-commit.exe "$@"</code></pre>\n\n<p>$@ expands to ALL arguments. "$@" expands to all arguments join by spaces. I suspect you shell script is incorrect. You didn\'t state exactly what you wanted the script to do, so that does limit our possibilities to make suggestions.</p>\n'}, {'answer_id': 54568, 'author': 'Vinko Vrsalovic', 'author_id': 5190, 'author_profile': 'https://Stackoverflow.com/users/5190', 'pm_score': 0, 'selected': False, 'text': '<p>Compare the environment variables in your shell and from within the script.</p>\n'}, {'answer_id': 54818, 'author': 'Luke', 'author_id': 327, 'author_profile': 'https://Stackoverflow.com/users/327', 'pm_score': 0, 'selected': False, 'text': '<p>Try putting "cd $1/hooks/" before the line that runs mono.  You may have some assemblies in that folder that are found when you run mono from that folder in the shell but are not being found when you run your script.</p>\n'}, {'answer_id': 55119, 'author': 'crashmstr', 'author_id': 1441, 'author_profile': 'https://Stackoverflow.com/users/1441', 'pm_score': 0, 'selected': False, 'text': '<p>After having verified that my code <i>did</i> work from the command line, I found that it was no longer working! I went looking into my .net code to see if anything made sense.</p>\n\n<p>Here is what I had:</p>\n\n<pre>\n        static public int Execute(string sCMD, string sParams, string sComment,\n                                  string sUserPwd, SVNCallback callback)\n        {\n            System.Diagnostics.Process proc = new System.Diagnostics.Process();\n            proc.EnableRaisingEvents = false;\n            proc.StartInfo.RedirectStandardOutput = true;\n            proc.StartInfo.CreateNoWindow = true;\n            proc.StartInfo.UseShellExecute = false;\n            proc.StartInfo.Verb = "open";\n            proc.StartInfo.FileName = "svn";\n            proc.StartInfo.Arguments = Cmd(sCMD, sParams, sComment, UserPass());\n            proc.Start();\n            int nLine = 0;\n            string sLine = "";\n            while ((sLine = proc.StandardOutput.ReadLine()) != null)\n            {\n                ++nLine;\n                if (callback != null)\n                {\n                    callback.Invoke(nLine, sLine);\n                }\n            }\n            int errorCode = proc.ExitCode;\n            proc.Close();\n            return errorCode;\n        }\n</pre>\n\n<p>I changed this:</p>\n\n<pre>\n            while (!proc.HasExited)\n            {\n                sLine = proc.StandardOutput.ReadLine();\n                if (sLine != null)\n                {\n                    ++nLine;\n                    if (callback != null)\n                    {\n                        callback.Invoke(nLine, sLine);\n                    }\n                }\n            }\n            int errorCode = proc.ExitCode;\n</pre>\n\n<p>It looks like the Process is hanging around a bit longer than I\'m getting output, and thus the <code>proc.ExitCode</code> is throwing an error.</p>\n'}, {'answer_id': 65070, 'author': 'apenwarr', 'author_id': 42219, 'author_profile': 'https://Stackoverflow.com/users/42219', 'pm_score': 3, 'selected': True, 'text': '<p>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 <code>proc.WaitForExit()</code> after reading all the data but before checking ExitCode.</p>\n'}]
['https://Stackoverflow.com/questions/54503', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1441/']