LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2005, 08:50 AM   #1
kooshball
LQ Newbie
 
Registered: May 2005
Posts: 16

Rep: Reputation: 0
running a program from within QT


i was tryign to make a gui in fortran, realized that's way too mcuh work and pain in the ass, so the easiest way seems to be make a interface to get the paramaters, output to file then run the program with the input from file. i got the output to file from the program fine, now all i gotta do is run the fortran program. so the question is, how do i run a program or a bash script from QT?

the QT program i have now is basicly a form and when i type in the info, i press a button everythign goes to a text file. what i want is to be able to press a button and have it run the fortran program that reads the data file in the background. that program would output to a file, then when the fortran program is done running, the gui program reads the output file then print it on the screen.

thx
 
Old 06-14-2005, 01:10 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
I don't think QT provides a method to run an external command. But that's OK because QT uses C++, so you can just use the system() function. See
Code:
man 3 system
You will need to include the stdlib.h header in the file you want to call system() from.
Then just do:
Code:
int rtn = system(command)
where command is a regular string (i.e. double-quoted or NULL-terminated; you can also use a QString here by passing the return value of its latin1() method). The string should contain the command to run, exactly as you would type it in at your shell's command line. See
Code:
man bash
for details on how to cope with command-line arguments and unusual characters.

After running this, the value of rtn will hold the return value of the command, assuming the command ran successfully.
 
Old 06-14-2005, 01:13 PM   #3
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 47
Quote:
how do i run a program or a bash script from QT?
I don't know QT, but I've heard the name qtProcess (or similar) and figured...
(GIYF)

You might also want to use your programming language's built-in interface to the shell;
in C and C++, that's `system', in python it's `os.system', for *, well GIYF

hth --Jonas
 
Old 06-14-2005, 04:45 PM   #4
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
Quote:
Originally posted by jonaskoelker
GIYF
www.acronymfinder.com is also your friend :)
 
Old 06-14-2005, 05:08 PM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Could you write the fortran program as a filter and have a bash or tcl wrapper piece everything together?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running a program LinAck Linux - Newbie 1 07-02-2005 02:17 AM
Running a program rj686 Linux - Software 16 10-10-2004 07:19 PM
need help running a program boogerman Linux - Software 8 11-24-2003 02:17 PM
Running a new program bananaman Linux - Newbie 4 04-08-2003 04:00 PM
Running a C program isaacais Linux - Newbie 3 12-11-2002 02:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration