Reading output from the command line - console-application

I'm trying to write a simple GUI for Wget. I'm looking for advice on how to read information from the command line output that Wget generates when it is doing a run. I'd like to update that download information real time to a list box or some equivalent. The GUI will be in Visual Basic. I know programs like WinWget do this, and their source code is available, but I don't know the language that's written in well enough to find what I'm looking for.
tl;dr: I need to update a list box real time with command line output.

There are two ways to use the output of one console application for the input of an other:
The first way is to use the | operator; for example:
dir |more
The second way is to write the data into a file and process it later.
dir > data.txt

Related

How to run a C++ Program interactive using external tools in gedit

I'm trying to run my C++ program interactively straight in gedit using external tools.
I've already written a Python tool for compiling it, but when using os.system("./program.out") all input for the program is set to 0 (but it is getting executed right, though).
Since using Python for executing it interactive would be rather difficult, im looking for another solution.
#!/usr/bin/env python3
import os
filename = os.getenv("GEDIT_CURRENT_DOCUMENT_NAME")
fout = "%s%s"%(filename[:len(filename)-4], ".out") #
os.system("c++ -o %s %s" % (fout,filename))
os.system("./%s" % fout)
the compiling works flawless, but ./program.out also doesn't give the wanted result using bash.
Any suggestions?
I guess i've found an answer. It may not be the most beautiful solution, but it works.
When defining a tool you can choose the input in a drop-down menu, there is an option for selected text as input.
So for example, if you have a program that reads 3 variables from stdin, you can add a comment to your code like //1 3 2, only select the numbers and then run your tool.
These numbers will be used as input in this order, somehow it only works with spaces.
A cruel way of implementing this would be to scan for input calls in the source code and ask for them via zenity in the gedit tool, i guess.
And here is another solution:
I can just use echo 3 2 1 | ./program.out in the tool
this makes everything way more easy

Best way to parse a complex log file?

I need to parse a log file that consist in many screenshot of real-time OS stdout.
In particular, every section of my log_file.txt is a text version of what appear on screen. In this machine there's not monitor, so the stdout is written on a downloadable log_file.txt.
The aim would be to create a .csv of this file for data mining purpose but I'm still wondering what could be the best method to compute this file.
I would the first csv file line with the description (string) of the value and from the second line I would the respective values (int).
I was thinking about a parser generator (JavaCC, ANTLR, etc..) but before starting with them I would get some opinions.
Thank you.
P.S.
I put a short version of my log at the following link: pastebin.com/r9t3PEgb

Creating and running a file with command line arguments

I am very new to linux and apologize if my descriptions are not savvy. I will try to be relevantly detailed.
Currently I am working on a terminal using Fedora, and my goal is to create a smaller data set to run a program. I was given an example, and my mentor said that to run the program all I had to do was type "./filename" into the console.
filename has command line arguments as follows: "./main ./textfile1 ./textfile2" Basically, each argument is separated by a space.
I tried recreating this document with similar format, but I am not sure what to save it as, nor does it work when I try running it the same way as the file with a larger data set.
Also, filename is bold in the terminal, whereas the document I created it is not. I'm not sure if this helps at all, but it is a difference I noticed.
Any help would be appreciated.
You need to set the execute bit on your file.
chmod +x filename
Make sure you compile the program first (in case you haven't. I use the g++ compiler typically) and then use the ./filename like your instructor said, but do not put "./" in front of the arguments. Just write it as "./filename textfile1.txt textfile2.txt"

Program Interaction and testing via bash script

I've just completed the coding section of simple homework assignment for my C++ class. The second part of the assignment requires us to verify our code's input validation. (The program takes several different values as inputs from a user and prints those values to a file)
I was hoping that I could use bash script for this. Is there any way to use bash script to run and interact with a program? How can I put the program's output into a variable (note that program has a series of input requests and outputs).
Thanks
To build on #Travis' answer, create two files: one holds your inputs (input.txt) and one holds the expected output (expected_output.txt). Then do the following:
./myprogram <input.txt >output.txt
diff output.txt expected_output.txt
If the diff command has any output, there's a problem.
You can do much of this with a shell script but you might want to consider using some other testing tools instead like CppUnit or expect.

Convert .odt .doc .ods files to .txt files

I want to convert all the .odt .doc .xls .pdf files to .txt files.
I want to convert these files to text files using a shell script or a perl script
There's a program for odt files and alikes:
odt2txt - avaliable in repos.
$ unoconv --format=txt document1.odt
Should produce document1.txt.
OpenOffice has a built-in document converter capable of handling a bunch of formats- take a look at unoconv: http://dag.wieers.com/home-made/unoconv/
That being said, I have had some troubles getting that to work in the past- If you're having trouble, take a look at similar programs for AbiWord (another open source word processor).
For word documents, you can try antiword, at least on linux. It's a command line utility that takes a word document as an argument, and spits out the text from that document (as best as it can figure) to Standard Output. Maybe you can specify an ouput file too. I can't remember the details of how it works. I haven't used it in a while. Not sure if it can handle OO documents.
It's certainly possible to do this, though there is something strange and impenetrable about the OO project and its documentation that makes things like this hard to research and follow. However, OO has the capability to convert all of those types, not just the OO native ones, and it can do it via two different forms of automatic control.
These are the two general approaches.
You can start OO and tell it to execute a macro which does this job for you for a given file. You then just have to write the macro and a script to loop over your files. The syntax is something like
$ oowriter -headless filename macro://dir/Standard.Module1.sMySub
The other thing OO has is a network API. This is based on something called UNO.
$ oowriter -accept=accept-string
Notifies the OpenOffice.org software that upon the creation of
"UNO Acceptor Threads", a "UNO Accept String" will be used.
You will need some sort of client library. I think they have one for Python at least. Using this technology a Python program or some other scripting language with an OO client library could drive the program and convert all the files. Since OO reads MSO, it should be able to do all of them.
Open the file in LibreOffice. Click on "File", "Save-as" scroll down to find the text option. Click that and it will be saved as a text file.
FYI, I had an *.ODT file that was 339.2 KB in size. When I save-as text the size of the file shrunk to ONLY 5.0 KB. Another reason for saving your files as text files.
For the Microsoft formats, look into the wvWare tools.
Open .ods file normally in libre office
Highlight text to be converted
Open a terminal
Run vi
Press "i" to get insert mode
Press ctrl-shift-v
Done!
Need some formatting?
Save the file as
Get out of vi
Run:
$cat | column >filename2
This worked in opensuse running KDE
Substitute "kwrite" for "vi", if you want