Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
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:

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

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:
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:

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:

earth-wind-and-fire:~/sep05 grahamellis$ tclsh fu4
oops - 1 - couldn't execute "ls -l": no such file or directory
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 and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

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