0

So I created an Azure Web Job that performs a certain task every 15 mins. It runs a C# console application. The problem is that on my last upload of my program I left my Console.ReadLine(); argument in, causing the program to never finish (used for local debugging of course) and the web job to fail and never run again. This can obviously be fixed real quick if I had the source code, but the source code is at my office, which I forgot to upload to my cloud storage. I won't have access to it till a bit later on this week.

So I'm looking for a quick fix. I can download the .exe program that was last uploaded easily. So now what I'm thinking is to run another program first that calls my main program and then closes it after a certain time. I tried a simple .bat script that was able to successfully open the program, but it couldn't close/kill the process due to access denied errors (worked locally). Any other quick suggestions that'll work in a web job environment?

Obviously if you see this here in a few days, I've probably already made corrections to the source code at the root of the issue, but others may be interested as well. :)

UPDATE:

Thank you to everyone! Each of these solutions helped me to get my web job running as intended. The decompiling using Reflector was especially useful so that I can add this project to the cloud like its suppose to be. However, using the run.cmd as suggested by @evilSnobu was the easiest and simplest way to apply a workaround as requested in my question.

Again thank you! :)

P.S. I switched from Console.ReadLine(); to System.Threading.Thread.Sleep(); to prevent any future mishaps.

Gerneio
  • 1,290
  • 10
  • 13
  • 1
    Can you decompile the executable to get at the source and recompile without the offending line until you can return to your office? – Clay Siefken Sep 12 '16 at 20:44
  • Always been curious about that, got a suggestion for a decompiling tool? – Gerneio Sep 12 '16 at 20:44
  • 1
    Back in the day, Reflector.NET was the go-to, but you might be able to get what you need out of ILSpy: http://ilspy.net/ – Clay Siefken Sep 12 '16 at 20:48
  • I forgot I already had .NET Reflector 9.0 installed! Checking it out now. – Gerneio Sep 12 '16 at 20:50
  • 1
    Worked! Code is a little off but still works as expected. – Gerneio Sep 12 '16 at 21:24
  • Nice! Yeah, decompiled code can be a little goofy. I've head huge programs I've had to maintain recovered entirely from lost-source binaries. It's not fun, but it'll get you by temporarily. Have a great week! – Clay Siefken Sep 13 '16 at 13:06

2 Answers2

3
public class Program
    {
        public static void Main()
        {
            Console.WriteLine("Hello World!");
            Console.ReadLine();
            Console.WriteLine("After ReadLine");
        }
    }

Try running your Webjob as echo '\n' | helloconsole.exe

Testing in Kudu:

D:\home\tmp>echo '\n' | helloconsole.exe
Hello World!
After ReadLine

D:\home\tmp>echo '\n' | helloconsole.exe
Hello World!
After ReadLine

..seems to pull it off.

If you drop that in run.cmd it will have precedence over your .exe binary. https://github.com/projectkudu/kudu/wiki/Web-jobs

We use the following logic to decide which file is the script to run within the job's directory:

  • Per file type we look first for a file named: run.{file type extension} (for example run.cmd or run.exe).
Community
  • 1
  • 1
evilSnobu
  • 24,582
  • 8
  • 41
  • 71
  • 1
    Oh, that's a good solution, which doesn't require violence! :) – David Ebbo Sep 12 '16 at 19:53
  • +1 haven't tried it, but it does look promising! I had actually just found my own answer moments before you two posted (link in comment of other post). Thanks for the tip on the run.cmd part! My quick and 'dirty' solution for that was to just put it in a sub directory. :) – Gerneio Sep 12 '16 at 19:58
  • what i can do if my web job is continuously running ... how to enter any input? – Neo Oct 13 '20 at 13:50
1

Try the following command to kill the process:

d:\devtools\sysinternals\pskill /accepteula YourProcessName

You can practice running this in Kudu Console first.

David Ebbo
  • 42,443
  • 8
  • 103
  • 117
  • Thanks for the reply! I actually just found a solution by following the answer in [this post](http://stackoverflow.com/a/451986). Worked well. I'll check yours out too though. – Gerneio Sep 12 '16 at 19:29
  • Try @evilSnobu's solution instead, which avoids the need to kill the process at all. – David Ebbo Sep 12 '16 at 19:54
  • Sorry to hijack but David can you look at this? http://serverfault.com/questions/802603/daemon-listening-on-a-port-make-port-accessible-from-network-requests-on-azure I'm not sure if Azure devrels are hanging out out on Serverfault – CQM Sep 12 '16 at 20:54