This forum has been archived. All content is frozen. Please use KDE Discuss instead.

kdialog's return value and exit code

Tags: None
(comma "," separated)
mvillarino
Registered Member
Posts
16
Karma
0
I would like to get to know about both the kdialog's exit code and the returned value.

My usage case is that of using it in shell scripting, like this:

declare variable=`kdialog --title"some title" --kindOfDialog someKind`

Then I need to either exit with error if the dialog was canceled or continue if it was ok. But #? is 0 always (the assignment is ok), and the value entered in the dialog can be the empty string.


Nihil difficile volenti
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Hmm, I'm not sure I understand your problem. For me the exit status of the dialog is 0 if it succeeds, else 1, and the text entered is written to stdout. Doesn't it work like that for you?

Greetings,
Sven


I'm working on the KDevelop IDE.
mvillarino
Registered Member
Posts
16
Karma
0
Yes, it behaves exactly like you sayd. That is the problem:

declare theResult=`kdialog .....`
if [ $? ]; then
# what to do if kdialog was cancelled
kdialog --error "You can not cancel to proceed"
exit 1
fi
#do something more
exit 0


The former script does not exits with exitcode 1. I assume it's because the last command executed is the assignment, and it is succesfull.


Nihil difficile volenti
wolfi323
Registered Member
Posts
1129
Karma
11
OS
mvillarino wrote:declare theResult=`kdialog .....`

Remove that "declare", then it should work... ;)
mvillarino
Registered Member
Posts
16
Karma
0
It works only in the shell command line.
Sample:
$ var=$(kdialog --combobox "Select one:" "alfa" "omega" --default "alfa")
#here you should press on cancel
$ echo $?
1
$ var=$(kdialog --combobox "Select one:" "alfa" "omega" --default "alfa")
#now on ok
$echo $?
0

Now, i don't get to a simple: if [ $? ]; then echo "ok"; else echo "cancel"; fi which happens to go the else branch


Nihil difficile volenti
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS
Code: Select all
if [ $? -eq 0 ]; then echo "confirmed"; else echo "cancelled"; fi


I'm working on the KDevelop IDE.
mvillarino
Registered Member
Posts
16
Karma
0
done by keeping the $? in a named variable

declare proceed
declare version

version=`kdialog --title "Version selection" --combobox "Select a version:" "trunk" "stable" --default "trunk"`
proceed=$?
if [ ${proceed} -eq 1 ]; then
exit 1
fi
unset proceed


Nihil difficile volenti
wolfi323
Registered Member
Posts
1129
Karma
11
OS
mvillarino wrote:done by keeping the $? in a named variable

Well, it works fine here without that.

And you don't really need to declare your variables. (although you can if you want to of course...)

This works fine for me:
Code: Select all
version=`kdialog --title "Version selection" --combobox "Select a version:" "trunk" "stable" --default "trunk"`
if [ $? -eq 1 ]; then
         exit 1
fi
echo "OK pressed, version=$version"
ataya
Registered Member
Posts
1
Karma
0
Just put exit at the end of your Bash or SH-Skript after eyerything is done or if the user dont choose the variables or your programm did not create the file you wisch:

Examples
file-there
fileth=$(find xyz -type f)
if [ "$fileth" = '' ]; then
kdialog --msgbox "Sorry Error bla bla"
exit 1
fi

target=$(kdialog --combobox "<font size=5>Choos suffix<font>" "mpg" "mp4" "avi" "DVD")

### the next if means (if usr do anything but choosing the offered variables (mp4, avi, DVD etc)
if [[ $target == '' ]]; then
kdialog --msgbox "<font size=6> Thanks for not choosing any thing, Goodbey <dont>"
exit
fi

if [ "$target" = mpg ]; then
bla
bla
fi
exit


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]