PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 16, 2022

[FIXED] How do I call a program from a GTK+ program, and analyze the program's output?

 August 16, 2022     analyzer, c, command-line, gtk2, output     No comments   

Issue

I am writing a GTK+ frontend program that shreds files. The program shred from GNU Coreutils is the backend. The programming language is C.

So, I have a progress bar that show how much of the shredding is finished. But, in order to give the user accurate data on how much is shredded, the output of shred must be analyzed.

So far I have tried g_spawn_command_line_async, but I am not able to send the output of shred to a file.


Solution

The easiest solution is using unix redirection. You can call system("shred -v file_to_shred > somefile.txt") and the output will be redirect to the file. You can then read from the file using POSIX read or some other file reading method. Run the system() call in a seperate thread, and the just incremently check the file in the main thread. You could use POSIX sleep() to check the file at some interval, say, every half second. However, never use sleep on the GUI thread, as this will freeze the UI.



Answered By - Lucas Streanga
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing