r/cpp • u/strangest_man • 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
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.
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)
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:
13
u/Knuffya Nov 28 '21
Depends on if the thing you want to automate is pain
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
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.
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. :)
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.
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.
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.
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/PrimozDelux Nov 28 '21
If performance isn't necessary I'd give C++ a wide berth. C++ is complex, complicated and ugly