Pyqt - Can not get any output from QProcess - pyqt

I have read a lot of similiar problems on SO and also anywhere on internet but i could not find solution for this.
i have the following command which i want to run:
c:\\lscc\\Programmer\\3.8_x64\\bin\\nt64\\pgrcmd.exe -infile test.xcf
From CMD window i have standard output like this:
Lattice Programmer Diamond (64-bit) 3.8.0.115.3 Command Line Argument
check - OK Loading Programmer Device Database... Done. Writing log
file to /programmer.log Opening XCF file... Done. Programming XCF
Contents... Connected to Lattice Cable Server. Failed.
I want to run it in my app via QProcess but i cant not find the way how to get same output.
I have following code, the command is performed and i cant get any output:
process = QProcess()
process.setProcessChannelMode(QProcess.MergedChannels)
process.start("c:\\lscc\\Programmer\\3.8_x64\\bin\\nt64\\pgrcmd.exe -infile test.xcf")
process.waitForFinished()
> process.readAllStandardError() = b" # empty
> process.readAllStandardOutput() = b" # empty
> process.exitCode() = -9
Only thing where is something usefeull is in errorString:
> process.errorString() = "Unknown error"

You are using the following method:
void QProcess::start(const QString &program, const QStringList &arguments, QIODevice::OpenMode mode = ReadWrite)
and clearly QProcess needs to differentiate between both so you must separate it:
process.start("c:\\lscc\\Programmer\\3.8_x64\\bin\\nt64\\pgrcmd.exe", ["-infile" "test.xcf"])

Related

os.system(cmd) call fails with redirection operator

My Python 3.7.1 script generates a fasta file called
pRNA.sites.fasta
Within the same script, I call following system command:
cmd = "weblogo -A DNA < pRNA.sites.fasta > OUT.eps"
os.system(cmd)
print(cmd) #for debugging
I am getting the following error message and debugging message on the command line.
Error: Please provide a multiple sequence alignment
weblogo -A DNA < pRNA.sites.fasta > OUT.eps
"OUT.eps" file is generated but it's emtpy. On the other hand, if I run the following 'weblogo' command from the command line, It works just find. I get proper OUT.eps file.
$ weblogo -A DNA<pRNA.sites.fasta>OUT.eps
I am guessing my syntax for os.system call is wrong. Can you tell me what is wrong with it? Thanks.
Never mind. It turned out to be that I was not closing my file, "pRNA.sites.fasta" before I make system call that uses this file.

Error "1132148 is not a hash" when running Perl program in Linux using Tk

I'm running Centos 7, Perl 5 and X11. In running a first time perl program copied from an online tutorial -
#!/usr/bin/perl
use strict;
use Tk;
my $mw = new MainWindow;
my $label = $mw -> Label(-text=>"Hello World") -> pack();
my $button = $mw -> Button(-text => "Quit",
-command => sub { exit })
-> pack();
MainLoop;
And then invoking from the command line -
./test.pl
I receive the following error -
[foo#localhost Desktop]$ ./test.pl
1132148 is not a hash at /usr/lib64/perl5/vendor_perl/Tk/MainWindow.pm line 53.
Aborted (core dumped)
After commenting out lines it seems the error is generated by the "my $mw = " line
Googling the error message I'm finding references indicating it might be an X11 known issue but not sure. Also not sure where to begin looking for an answer.
I have (using yum) double checked to make sure tk, perl-tk and tcl are up to date. I've attempted to check the status of the X installation but am a little fearful of reinstalling lest I make things worse.
The comment from mbethke leads to what is the real problem with this specific error.
In fact, on Linux, you can quickly check if Tk is properly working or not by using the wish command (that should open a small window).
When you have the problem, wish does not open and outputs the following
unknown color name 'BACKGROUND'
And since wish and this error are more common than some Perl & Tk scripts, you can find more answers, such this one, in which one you find a way to clear the color defined :
xrdb -load /dev/null
xrdb -query
(xrdb -query is used to check the current color configuration.)
Then, everything should be fixed.

capture process output in Groovy

I have a Groovy script that recurses through a directory looking for .png files, and invokes pngquant (a command-line utility) on each of. The output of pngquant should be printed on the terminal. The relevant code is:
def command = "pngquant -f -ext .png"
root.eachFileRecurse(groovy.io.FileType.FILES) {File file ->
if (file.name.endsWith('.png')) {
println "Compressing file: $file"
def imgCommand = "$command $file.absolutePath"
Process pngquantCmd = imgCommand.execute()
pngquantCmd.consumeProcessOutput(System.out, System.err)
}
}
The script works fine, but once all the files have been processed, it seems that stout is still being redirected, because the command-prompt never appears unless I kill the process with Ctrl + C. Do I need to somehow "undo"
pngquantCmd.consumeProcessOutput(System.out, System.err)
or is there a better way to redirect the output of this process to the console? I guess I could solve this problem simply by adding System.exit(0), but this doesn't seem like the right solution. The problem only occurs on Linux.
Instead of
pngquantCmd.consumeProcessOutput(System.out, System.err)
Which will start a couple of threads to read the outputs and plough on regardless of the process' situation, you should try
pngquantCmd.waitForProcessOutput(System.out, System.err)
Which will redirect the process output and then wait for it to finish before moving on :-)
You can also do
Process pngquantCmd = imgCommand.execute();
def output= pngquantCmd.text;
println("Output : " + output);

linux - export output from apachetop to file

Is it possible to export output from apachetop to file? Something like this: "apachetop > file", but because apachetop is running "forever", so this command is also running forever. I just need to obtain actual output from this program and handle it in my GTK# application.
Every answer will be very appreciated.
Matej.
This might work:
{ apachetop > file 2>&1 & sleep 1; kill $! ; }
but no guarantees :)
Another way using linux is to find out the /dev/vcsN device that is being used when running the program and reading from that file directly. It contains a copy of the screen data for a given VT; I'm not sure if there is a applicable device for a pty.
Well indirectly apachetop is using the access.log file to get it's data.
Look at
/var/log/apache2/access.log
You'll simply have to parse the file to get the info you're looking for!/var/log/apache2/access.log

Execute shell commands using popen in c++

I need to be able to execute some shell commands such as moving to the right directory where I have some files I need to decode and then decoding them using another command. I read some stuff about using popen but I didnt really understand how to use it for executing multiple commands.
Any pointers will be greatly appreciated :)
Thanks
FILE *pf;
char command[150];
char data[512];
// Execute a process listing
sprintf(command, "cd");
pf = _popen(command,"r");
sprintf(command, "cd Test_copy");
pf = _popen(command,"r"); */
sprintf(command, "java -jar Tool.jar -b x.fit x.csv");
pf = _popen(command,"r");
if(!pf){
fprintf(stderr, "Could not open pipe for output.\n");
return;
}
// Grab data from process execution
fgets(data, 512 , pf);
// Print grabbed data to the screen.
fprintf(stdout, "-%s-\n",data);
if (_pclose(pf) != 0)
fprintf(stderr," Error: Failed to close command stream \n");
Use ShellExecute to play with files (open with default application etc.). Use system to run shell commands.
No, don't. That would be like using a sledgehammer to knock on a door. Furthermore, it is "evil": http://www.cplusplus.com/forum/articles/11153/

Resources