Capturing console output from a .NET application (C#)
I'm wanting to do a similar thing that is asked in that question except that I am using c++ and not c#. I have a small well tested java application that has some functions that are about to be rewritten in some of my c++ code and I'm wanting to write some unit tests for this using boost unit to test that the results are the same. Essentially I want to call this java command line application from c++. I'd rather not use the JNI if at all possible so executing the other command line application via the c++ code would be preferred.
How do I invoke a console application from my c++ application and capture all the output that is generated in the console? (I'd very much rather not have to write to an intermediate file but if that's the only way to do it then so be it)
It seems like this should be somewhat straightforward but I'm having a huge amount of trouble finding anything by searching the web as the keywords tend to find results about other things (c# and compiling from command line being 2 examples). I wouldn't be at all surprised if this question is a duplicate but I cannot find another question that is the same. If it does already exist I'm more than happy to close this question upon a link to the other one being found.
It depends on the operating system you're targeting as there's no process handling functionality in the standard C++ library. On Windows for example you would create two pipes (using the CreatePipe function) to redirect the Java app's input and output, and then run the Java app using the CreateProcess function. There's an example of this here.
But I'd really recommend using JNI instead, which is a light-years better form of interop/IPC than pipes. You'll eventually realize that if you go the pipes route.
Related
I'm working on an interactive command-line tool. The tool shows a prompt, and the user can enter commands and parameters which are being processed. After a command was executed, thhere is a new prompt and the user can proceed entering commands. It is very similar to gdb debugger, when used in cli mode.
The tool is mostly written in C++, with some wrappers for using C librarys.
I'd like to attach a GUI (QT would be my first choice here) to my tool, however, I'm not sure how to do this.
If you search the internet, many Unix developers prefer to strictly separate back- and frontend.
So, I'm thinking about making the GUI a separate executable, which just uses the functionality of my command line tool.
What's the best way to achieve this?
Should I use interproces communication with pipes or sockets?
gdb, for example, uses TCP/IP, allowing to even run the GUI not on the same machine as the server! (However, this feature is not necessary).
If using some kind of IPC, how should the communication work? Should I use an ASCII interface (The Art Of Unix Programming prefers this)? This would have the advantage that my GUI just needs to parse the output of my command line tool. I don't have to change my tool very much, because it does not make much difference if the tool writes to a socket/pipe or just to cout.
If so, should I define a protocol for IPC or just parse the input/output?
Another way would be to integrate the GUI to my tool directly, resulting in just one executable. Insight debugger does it this way. Insight not just "uses" gdb, it has its own gdb in its programm code.
This way I won't have to write a parser, my GUI code can just call functions from my "base code".
Or should I make my command line tool a library, which I can link with a cli- or a GUI frontend?
What would be the best way to solve my problem?
What are the avantages/disadvantes of the solutions above?
What do you prefer?
As you noted in the question, there are several ways you can architect two pieces of software. There are three questions you want to ask yourself:
what's the relationship between the two code segments.
how likely is each code segment going to change in the future.
how is your code going to be deployed
If one code segment is strictly a layer of abstraction on top of the other layer (the CLI code in your case), the core CLI functionality is relatively mature and stable, whereas you find it likely the the GUI will likely change often, this might suggest that you make the CLI code a library, and have the GUI code include the library and "call down" to the CLI code. If, on the other hand, the GUI code ties a bunch of pieces of software together, whereas the CLI code is a smaller, more isolated module and will likely change at a higher frequency rate (think dvd inside a dvd player) you might consider making your GUI a framework that imports different 'engines', or CLI modules. If you expect the two code segments to have a side-by-side relationship, for example the GUI might make HTTP requests to download images while the CLI code might do some CPU intensive number crunching in the background, then you might want to explore having both the CLI and GUI running as separate threads and communicating with other. [Depending on how closely coupled the two code segments are you can explore separate threads (no coupling), occasional message passing (message-queues) to using threads and fine-grained locks (very tightly coupled).]
separate processes (with the optional socket interface to run on different machines) are very useful when breaking down large software deployments into smaller, modular units. As long as your code can still fit in your head, and is less than roughly ~10,000 lines of code the added code complexity and latency isn't justified.
From your description it sounds as though the CLI code is mature, and the GUI is going to be simply a shell which interacts with the CLI. I also understand that you intended to ship your code as an executable. Therefore I think your use cases falls in line with making your CLI code a library, and writing a CLI shell and GUI shell that interface with it.
I have a few vbscript/javascript html applications that I will be distributing online( all for windows only). Just small apps, nothing fancy.
My main experience lies with .net and java.I really want the app to be standalone , requiring no installation, and everything in one file. But not letting my users be able to see the code is important too, which doesnt work with vbscript based hta
While I could spend some time doing it all over in c++ and then statically linking to create an independent and happy .exe file, but I will have to spend considerable time brushing up my c++ skills, which are intermediate-ish.
Can I "cheat" and still write the whole application in vbscript/javascript but do something like this in c++ ( pseudo-code below)
#include headerfiles etc
read the vbscript code stored in a variable perhaps?
create a .hta file, put the code in that and run it in Internet explorer
get window handle for internet explorer ,
disable right click( to hide view source option)
Then compile this c++ file and statically link it and distribute my super cool standalone .exe file.
Is this a naive approach? Does it make sense? Yes I *could*learn c++ but if this does the job, I can keep focus on my .net applications which are my main bread and butter. And I can simply use Html to do my user interface rather than using something like QT. Hiding the source would have been nice but it is not super-essential or a dealbreaker, as the app is not commercial anyway. My point is , is there a serious drawback to this approach?
Thank you :)
You're effectively trying to wrap the VBScript/JavaScript code in a native executable that would output the script to a file and then run it. This wouldn't prevent reverse engineering at all - it would only be a very slight hindrance to someone who wants to see your code.
If you reprogrammed your application in C++ completely, it would be somewhat more difficult to construct the source code that is equivalent to the original. However, hiding the source code completely is not possible: if it can be executed by the processor, it can also be reverse engineered.
Hei there, I'm not experienced at all in C++ as I need to start learning year the next year at my university, though, I've been creating a browser based game and I'm looking for someone to transform it into pc app.
Though, I'm wondering how to make that application send a http request via POST to a file on my webserver with the username / pw.
After all the tutotials I've been reading, I concluded that none worth spending my time with, because they all based on own database, and I'm looking for one that connects to a maestro server and requests the data from there.
This may not be the answer you are looking for, but you may consider two alternatives to a more pure C++ application.
If you already have a working browser game, try to take that same code and put the html/javascript/whatever in a file and give the file a ".hta" extention. It basically opens inside a browser to run your files, but it acts more like an application from the user's viewpoint. (And, as much as I hate Windows, they're pretty fun to create if I may say so). However, your source code with this option is easily read because it can be renamed to a text file (or html file).
You could use Visual C++ (or VB.net, which you have tagged to the question, as well as "Visual" C#) to create an application which mostly consists of a browser view. It could be a "standalone" application (however would rely completely on the .Net framework - may or may not be what you want) that basically accomplishes the same as the option above, but adds that you can "hide" your files inside your application.
Using the two above alternatives, you could make an application relatively quickly that would load your files, which I assume you have already created. Note that neither of the above alternatives will work on anything other than Windows OS's.
If the two above alternatives are not what you want, or if you have questions about either one, I'd be glad to attempt to help.
I've been able to find a friend that would do it in Delphi because I wouldn't want users to download net framework just for this ap.
So the program that would fit most for any apps is Delphi Prism XE (even if it's an addon of Visual Studio)
I'm looking for a way of editing and save a specified cell in Excel 2010 .xlsx file from Node.JS. I realize, that maybe there are no production-ready solutions for NodeJS at this time. However, NodeJS supports C++ libraries, so could you suggest me any suitable lib compatible with Node?
Also, I had an idea to process this task via Python (xlrd, xlwt) and call it with NodeJS. What do you think of this? Are there any more efficient methods to edit XLSX from NodeJS? Thanks.
Basically you have 2 possibilities:
node.js does not support C++ libraries but it is possible to write bindings for node.js that interact with a C/C++ library. So you need to get your feet wet on writing a C++ addon for the V8 (the JavaScript engine behind node.js)
find a command line program which does what you want to do. (It does not need to be Python.) You could call this from your JavaScript code by using a child-process.
First option is more work, but would be result in faster executing time (when done right). Second possibility is easier to realise.
P.S.: To many question for one question. I've no idea about the xls-whatever stuff, besides it's "actually" only XML.
I found an interesting article from HP website. They wrote a TouchSmart Shell application, and it allows other applications to embed in that shell, and run as a separate process. Of course, HP defined some restrictions with the embedded application. I don’t know if C++ and Win32 can do similar thing?
http://www.touchsmartcommunity.com/article/95/An-HP-TouchSmart-Application-Development-Guidelines-Primer/?textpage=1
Isn't this what all the unix shells do? Embed applications into themselves. I hope I have understood your question correctly. A similar thing can definitely be done in Win32. MSYS (Minimal SYStem) and Cygwin all do the same. They have their own shells, though I would assume they're written in C and not in C++
Maybe I've missed something, but TouchSmart just looks like a way of starting a .NET application from within it. There are probably some API's that you need to call into for correct presentation or events to hook up to.