Training, Open Source computer languages

This is page http://www.wellho.net/forum/The-Tcl- ... guage/Error-when-running-C-application-with-exec.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Error when running C++ application with 'exec'

Posted by Dimon (Dimon), 23 September 2005
Hi all.
My Tcl/Tk application is a GUI for C++ program, it calls C++ program with different command line parameters. All still worked correctly but at the end of developing I found a unanderstandable error. When I customary call C++ program with 'exec' command, I recieve an error:

Code:
couldn't execute "D:/TestRider/TestRider.exe -BuildTable D:\\TestRider\\Tables\\Devices\\cat2my.cmt -NewDeviceName cat2my -TesterTable D:\\Tables\\Testers\\CAT2.csv": invalid argument

where:
TestRider.exe - my C++ program
-BuildTable, -NewDevicename, -TesterTable are the keys
Paths are a values for corresponding keys.
Double slashes need for correct parsing inside c++ program.
The calling string is:
Code:
if [catch {exec $directive} errmes] {
.......
}

Where value of 'directive' variable shown up.

If I run that command like standalone tcl script with tclsh84 or wish84, C++ program called and work correctly. But when I call it from my own Tk-shell, it return the error showed up.
I don't know what to do 'cause I call this C++ program many times in my Tcl/Tk application and it work correctly!
Any ideas about what I made wrong and how to fix this error?

Posted by admin (Graham Ellis), 24 September 2005
I think the problem is that you have your command name and parameters all in the same variable that's passed into the exec, so that your program is looking for a command who's name is the entire command line and not just the command name.

Here's an example that I hope clarifies that:

Code:
set directive "ls -l"
if [catch {exec $directive} errmes] {
       puts "oops - 1 - $errmes"
       }

set directive "ls"
set opt "-l"
if [catch {exec $directive $opt} errmes] {
       puts "oops - 2 - $errmes"
       }

puts "done"


The first section gave an errot message (as per your report) and the second section worked.    Here's the output:

Code:
earth-wind-and-fire:~/sep05 grahamellis$ tclsh fu4
oops - 1 - couldn't execute "ls -l": no such file or directory
done
earth-wind-and-fire:~/sep05 grahamellis$


Posted by Dimon (Dimon), 26 September 2005
Oh, thank you, simple and interesting.
But I have solved this problem by calling that C++ program in separate thread   More complex but it's working.




This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho