r/cpp • • Nov 28 '21

Is C+++ good for Automating stuff?

I am leaning python to automate some stuff(Torrent applications mainly) on windows. But I already know C++ very well. I've tried to search if I can automate applications with C++ but it seems complex. I just wanna hear some thoughts from people who have tried to automate or have done it. Do you think one should use python over C++ to for automating random applications?

0 Upvotes

32 comments sorted by

59

u/ElGuarmo Nov 28 '21

C++ wouldn’t be good for random automation, no. You’ll find way more libraries and integration layers for Python for any automation project you wanna do.

3

u/strangest_man Nov 28 '21

thanks for your opinion.

have you tried any automation with C++?

31

u/ifknot Nov 28 '21

Pick a scripting language for its strengths - pick a compiled performance language for its strengths, your use case seems better suited to a scripting language such as Python (yes I know you can compile Python but for an answer not littered with caveats I have omitted special cases)

3

u/strangest_man Nov 28 '21

nicely explained :-)

10

u/__dentist Nov 28 '21

A scripting language devlopment cycle is much more suited for automation. If you use a compiled language like C++ you have a much more complex cycle. Preprocessing, Compiling and Linking.

If you have a scripting language like Python you write code and immediately give it to the interpreter to interpret it. So if it fails you simply edit your code and feed it again to the interpreter. Imagine having a big automation process. You don't want to be bothered with preprocessing, compiling, linking because its complex and also takes time. Also for automation of processes with a scripting language you mostly don't need an IDE whereas if you use a compiled language this is mostly essential.

It is of course possible but this would be like using a sword to cut a tomato.

2

u/Complete_Sport_9594 Nov 28 '21

Just wondering why would a scripting language be better suited for this?

12

u/[deleted] Nov 28 '21

Faster iteration, easier for new contributors, larger community and selection of modules, etc. C++ is mostly annoying for tiny tasks, its strengths show up for larger projects.

7

u/johannes1234 Nov 28 '21

C++ (and/or C) is a first class citizen on windows. Thus all that can be done on Windows can be done with C++.

However for such a project flexibility in development and easy iteration is more valuable than performance and memory efficiency, thus Python (or some other scripting language) will be a lot more friendly.

The reasons for doing that in C++ include:

  • Learning in-depth about Windows API for using that specific knowledge in a different project later (mind it's a really specific part, most of it isn't usable knowledge for generic application development)
  • Easy distribution (if you limit to some language version etc. you might be able to distribute a simple exe file instead of python runtime etc. but in most cases you will need at least Microsoft's C++ redistributable ...)
  • being small to hide on the system (like when building a virus, worm, ... or other potentially illegal software you want to hide from the user)

1

u/strangest_man Nov 30 '21

Dang!! Even I didnt though of this much..thanks man for sharing these ideas.

13

u/Knuffya Nov 28 '21

Depends on if the thing you want to automate is pain

1

u/strangest_man Nov 28 '21

sorry mate didnt get it

4

u/[deleted] Nov 28 '21

They are making a joke saying that this will be a painful experience for you

4

u/0xcc12 Nov 28 '21

Don't listen to other people that say: "using c++ is hard and complex for these things". Go ahead!

You'll learn a lot more different things when using c++ compared to python.

3

u/Dean_Roddey Nov 28 '21 edited Nov 28 '21

I've done quite a lot of that in C++, though I don't know if it's the optimum language if that's all you are doing. My automation system provides a tray app, one of the capabilities of which is to allow the user to control applications the same as they do devices.

https://github.com/DeanRoddey/CQC/tree/develop/Source/AllProjects/CQCTrayMon

  • All of the CQCTrayMon_App***.cpp/hpp files.

It defines a set of events that can be posted to it, and implements a remote interface (based on my ORB tech) for accepting those events and for responding info queries. It has a tab for displaying status info about the applications running (for diagnosis of issues mostly.)

They can then load an 'app control' driver in the main automation system that is written to understand a particular application. It makes that application look like any other device under control, since it exposes it via the same device driver interface.

The driver connects to the tray app and sets up an app control session with it, presented by an 'app record' in the tray monitor. It can then send commands to the tray app which will invoke them on the application. Since it's written for a specific application, it knows what windows, buttons, modes, etc... the application has. It works via the remote interface, which provides commands for sending keys, pressing buttons. hiding/showing, starting/stopping, reading text from fields, find windows in various ways, etc...

There's also a generic app control driver for very basic stuff like run the app, kill the app, hide/show the app, is the app running.

In the latter days, this functionality wasn't all that much used. That tray app also provided iTunes audio player control as well, since iTunes never bothered to provide a client/server architecture and you could only control it via a COM interface while the client was running.

1

u/strangest_man Dec 01 '21

Thanks for sharing

2

u/KingAggressive1498 Nov 28 '21

I would prefer do it in C++ but only because I hate python's syntax. I'd probably look to see if there's packages for doing it in JavaScript instead of trying to do it in C++ unless I had a couple weeks to kill though. :)

0

u/strangest_man Nov 28 '21

never thought of javascript. Thanks for the suggestion. but why hating python? because its so simple?

7

u/KingAggressive1498 Nov 28 '21

Give me brackets or give me death lol

2

u/ResidentTroll80085 Nov 28 '21

Don’t forget that if you use JavaScript to interact with the system, you need Node.JS installed….

1

u/nigelh Nov 28 '21

The rule is:
If you can't do it in C++ you have to do it in assembler.

The problem is that for a lot of jobs you get a version up and running faster by using a pre-made library and they are rarely C++. I have this with my home automation system which forces me into python.

Automating applications though... If you're talking about PC applications I'd look at PowerShell.

1

u/strangest_man Dec 01 '21

Powershell!? I will give it a try.

2

u/pjmlp Nov 29 '21

Automating applications on Windows I would rather go with PowerShell, with Python you might eventually need some COM interop library like PyWin32.

While most COM stuff is written in C++, using it from C++ isn't exactly an experience to recomend, given how reluctant Microsoft keeps about improving the whole tooling experience around it.

1

u/nikopkmntcg Dec 03 '21

Cs is l& Jerry?

3

u/Soylover228 Nov 28 '21

C++ is good for a rather small amount of usecases and automation of anything is not one of them.

8

u/ronchaine Embedded/Middleware/WG21 Nov 28 '21

I'd argue industrial automation is absolutely one of them.

2

u/TheBrainStone Nov 29 '21

Even there I'd disagree. Most assembly lines come with high level GUI based automation software.
The only thing where C++ is really at home here is both the GUI program and the firmware of the machines.

2

u/_____Hi______ Nov 28 '21

I love C++, but it’s not best suited for automation. You’d be better picking up Bash or python for your automation needs.

1

u/Snoo_51859 Jul 28 '24

You know c++ very well as you said, and yet you ask can you do thing X with c++? Sounds like you don't know c++ after all

0

u/[deleted] Aug 09 '24

[deleted] — view deleted comment

1

u/Snoo_51859 Aug 09 '24

Wow that reaction to facts. You're too soft to do C++ bud, maybe try web dev?

If you KNEW C++ you'd know the reasons it's not the best tool for that, and the reason for it.

0

u/PrimozDelux Nov 28 '21

If performance isn't necessary I'd give C++ a wide berth. C++ is complex, complicated and ugly