0

I am running some Stata code which calls the Windows command prompt in a recurring loop once every second. Every time it does this, a new instance of Windows Command Processor launches in the foreground, executes the command, and closes. This is very inconvenient, because it effectively prevents me from using my computer to work on other tasks: every time the command processor launches, whatever I am working on is sent to the background for a second.

Is there a way I can set the command processor to always launch in the background, or some other workaround for this? If relevant, the command I am executing is a curl GET request.

Note: I have tried preceding the command with "start /b" -- this does not work.

3
  • Can you not launch curl.exe itself in the stata loop instead of cmd.exe? I think you'll need to share some code, hopefully someone who knows stata would have an actual answer to use their scripting language effectively.
    – Romen
    Nov 16, 2022 at 22:30
  • No -- Stata cannot natively run a .exe file. That's why the -shell- command exists in Stata -- it enables you to send commands to the OS command processor.
    – user770884
    Nov 16, 2022 at 22:49
  • If you make a shortcut to a .bat file, or to CMD, the properties of the shortcut can be set to open the command prompt minimized. Whether Stata can call that shortcut is another question, though. See also stackoverflow.com/questions/23057448/… Nov 16, 2022 at 22:56

1 Answer 1

1

To be honest.. I know very little about stata.. but I do know how to RTFM and hack crap to make it do what I want (usually). I don't have stata but I can tell you your options and how to get around this atrocity.

I myself am a programmer so I have an infinite amount of tools in my belt but you will need to work with what you have.

No -- Stata cannot natively run a .exe file

Sure IT CAN!. Stata does not force you to use the shell command (or ! for a shortcut). Unfortunately, this comes with some caveats.

This new option will require some creativity on your part to solve your problem.

Stata supports the winexec command (which tells you how old it is). winexec was part of the Windows 16bit api (as in PRE-WINDOWS95).

Here is the tricky part for you about using winexec instead of shell.

  • shell only runs crap through cmd.exe and suspends stata and pulls the shell into the foreground until it completes. Then returns you to stata. The behavior you don't like here is BY DESIGN! Stata is actually pulling the cmd.exe window to the top ON PURPOSE! You aren't likely to hack your way around it. I myself can think of simple ways.. but they all require some programming knowledge (enough to make a simple .exe program) or beginner hacking skills.

  • winexec allows you to run any darn thing you want.. complete with command line parameters! But wait.. DARN IT! winexec doesn't wait for your curl thingamajigger to finish before returning you to stata.

If that won't work, we have ourselves a conundrum and you will have to be creative to solve it.

At least NOW, you have some options to work with.

Think of when you press ⊞ Win + R and the Run dialog comes up. That is basically what winexec gives us. Imagine if the second you hit enter, it returned to stata.

When you say curl runs in a recurring loop once every second.. this is highly doubtful.. but I guess possible. Stata needs to call the shell funtion causing windows to fire up the command processor and open curl. Curl would need to handshake, connect, download something and close. That will probably take more than one second. The thing is.. shell WAITS which makes me wonder what your timer is actually timing.

You could run curl directly with the winexec command but you don't want them getting backed up as they will keep executing even if the prior one hasn't finished. You could figure out ACTUAL time it take to run and work that into your timer loop.

Another option would be to run a batch file minimized. You would need to add .LNK to your PATHEXT environment variable to call a shortcut using winexec. This batch file could drop a file that you could look for in stata to signal that it finished. On the stata side, you would use the fileexists function then delete it and continue.

I can think of several hokey ways around this but it is late and I need to go to work in the morning.. You are going to need to figure out how to work in winexec for yourself. If I think of a good way... I will add to this.

Feel free to comment with any questions..

The dumbest idea of ALL!
Stata is a paid program. It's so FREAKING EXPENSIVE that the best you can do on the site is "request a quote" for a cost. ASK SUPPORT! Those guys know how to hack their own crap even better than the devs that wrote it. Trust me, I did support for years. If anyone knows, they know and would probably be happy to help.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .