Programming :: Getting Return Value From Program Ran In Background?

Mar 10, 2010

I think my title pretty much explains it. I am writing a script and I want to start a program in the background, and when that program finishes I want to check the return value to make sure there was no error.For example normal I would do something like this:

#!/bin/sh
program
if [ ! $? -eq 0 ]; then
echo "There was an error"
exit 1
fi

Now I want to do something like this:

#!/bin/sh
PRTN=`program1 &`
program2
if [ ! $? -eq 0 ]; then

[code]....

In this case if program2 finishes before program1, I don't think the return value from program1 $PRTN would be valid at the time it is checked.

View 3 Replies


ADVERTISEMENT

Programming :: Running Program In Background From Script

Mar 27, 2011

I have a script that calls another program/script, xxx, to run in the background. Supposedly this program at most should finish within five (5) minutes so after five (5) minutes, I run some other steps to run the script into completion. My problem is sometimes the program takes longer than five (5) minutes and this is causing problems when running the rest of the steps in the scripts. Can anyone suggest how to re-program my script. At the moment, the KSH script, i.e. test.ksh, is doing as below:

test.ksh:
.....
.....
xxx/xxx.ksh <--- program/script called by the script
sleep 300
..... run the rest of the script .....
..... problem is sometimes xxx/xxx.ksh takes longer than 300 seconds .....
..... any way that I can monitor that xxx/xxx.ksh finishes before I run .....
..... the rest of the scripts .....

View 3 Replies View Related

Programming :: Continue Execution Of A Python Program While A Background Task Is Going On?

Aug 28, 2010

I'm trying to figure out how to continue execution of a Python program while a background task is going on.

In bash, it is adding "&" to the end as in:

Code:
#! /bin/bash
find / -iname "*.py" > /tmp/all_pys &
echo "looking for all python scripts and putting them in /tmp/all_pys"
(yes, I know I could just put the echo BEFORE the find but I just use it for example)

Say I do that in python (not necessarily running the shell, but perhaps using scriptutil.ffind or something similar), but want to allow the user to be doing something else while running that search in the background, how would I thread, fork, subprocess (not to be confused with the module and Popen) [or whatever I should call it] that?

View 14 Replies View Related

Ubuntu :: Run Program From CLI Then Return?

Jan 9, 2011

I'm trying to figure out the syntax needed to run a command that will spew out output (which I don't need) but go back to allowing me to run other commands without closing that program.Basically I run:

Code:

./utserver

and it starts and gives output but I want to run other commands without needing to open a new tab or close that program.

View 4 Replies View Related

Programming :: Termios Programming - Without Removing Carriage Return / Enter Key

Jun 30, 2010

I trying to write a UART(interfacing of serial devices) to linux machine but after I execute the following code to receive data I need to enter key (carriage return).... but I don't want to remove carriage return/enter key

[Code]....

View 13 Replies View Related

Ubuntu :: Run Program In Background?

Jan 17, 2011

I frequently run teamviewer on my netbook because it's my favorite remote desktop application, but it doesn't have an option to run at startup nor hidden. This is what I need:o be able to run teamviewer automatically at startup, hidden as a "service?" (meaning no taskbar button nor tray icon) and with a delay of 20 seconds (it has to be started after my wifi has automatically connected, not before).Can't be so hard, but I don't seem to be able to find a good answer to this in Google.

View 4 Replies View Related

General :: Alias To Run A Program In The Background?

Mar 4, 2011

I'm running Utorrent server and I figure I would create an alias to launch the program and run it in the background.alias utorrent='/home/user1/software/utorrent-server-3.0/utserver &'It seems to run the program but the associated webui program is flaky and won't start correctly.If I manually go to the specified path and run the command ./utserver & , I never seem to have an issue with the webui.I was wondering if this could possibly have anything to do with using the '&' ampersand operator in an alias.

View 2 Replies View Related

Programming :: Else &amp; Return Values?

Oct 12, 2010

i am having two small issues with a function i have made.sorry if it is a mess, i am still learning bash.the first is calling the nonpersistssh function (second line) and assigning the return value to nonpersistdiag.the function returns 1, but nonpersistdiag seems to only contain 0. i am unsure on how to proceed.the second problem is the nested else clause on line 10. it is a syntactical error. how would i declare it correctly?

Code: function endsession(){
nonpersistdiag=$[nonpersistssh]# a function that returns an exit code
sudo /etc/init.d/ssh stop; sshdiag=$?

[code]....

View 6 Replies View Related

Programming :: Return And Exit In C

Jun 3, 2011

What are the uses of return 0, return 1 and exit statements in C

View 4 Replies View Related

Programming :: Return Value From A Function?

Nov 15, 2010

On this link [URL]4 a return type is defined

Code:
return ((unsigned int)(unsigned long)base & TBASE_DEFERRABLE_FLAG);
What is the above function returning.I am not clear with definition of what is being returned in the above code.

View 7 Replies View Related

Programming :: What Exactly Does Echo $0 Return

Jan 18, 2010

I'm confused about what "echo $0" in a shell actually return. Consider these tests:

Code:
[root@e11apvl151 ~]# # Login shell:
[root@e11apvl151 ~]# echo $0
-bash
[root@e11apvl151 ~]# # Starting a new shell
[root@e11apvl151 ~]# bash
[root@e11apvl151 ~]# echo $0
bash
[root@e11apvl151 ~]# screen
[root@e11apvl151 ~]# echo $0
/bin/bash

Depending on wether the shell is a login shell, a regular shell, or a screen utility, I get different results.

View 8 Replies View Related

General :: Running Program In Background In Child Emulator Process

Aug 26, 2009

I wonder how one can, if at all, run an X program in the background *in an emulator sub-shell process*. What I mean is to launch a program in an emulator, e.g, by xterm -e gedit

but with gedit (in this example) running in the background from inside the xterm sub-process, so that the xterm will accept other commands. In the above, gedit will run in the foreground, and of course, if you do
xterm -e gedit &

then xterm will run in the background, not gedit.In short, I would like to achieve the same thing as "gedit &" as you manually do in xterm, but from another shell. What I aim to do is write an X init script to achieve this result (to have the emulator open and a program or two running from it, in the background, at the X startup).

View 2 Replies View Related

Programming :: Tell If Grep Didn't Return Anything?

Mar 15, 2011

I have a file:

979798707
787862348
766428634

I want to see if all the records in the file are present in the contents of the files of a particular directory.

Basically I want to say if grep doesn't return anything, then report.

For example in /tmp dir I have 4 files and flast 2 values (787862348 and 766428634) are present in the files of /tmp dir, but first one (979798707) is not. I want to echo that in a reporting file.

something like:

while read line
do
# if ! grep -rl $line /tmp
echo $line >> are_not_present
done < "myFile"

How do I achieve " if ! grep -rl $line /tmp"? That is, if the line is found by grep, then grep will print the output, but if grep does'nt find it, it will print nothing. How can I check if grep didn't find it (i.e. printed nothing)?

View 2 Replies View Related

Programming :: C - Return To The Beginning Of A File?

Dec 16, 2010

I'm reading a text file with fscanf using a loop until feof(inFile). How can I return to the top of the file? As in I have one loop that scans until the eof and then after it there's another loop and I want to start from the beginning of the file again scanning to the end of it. How do I get back there?

View 3 Replies View Related

Programming :: Echo Hello Command Does Not Return

Jan 11, 2010

I am testing the serial ports on a Single Board Computer(SBC) running Linux kernel 2.6.29. I usually do this by connecting the serial port to another PC serial port, then doing "cat /dev/ttyS0" on PC and "echo hello > /dev/ttyS0" on the SBC. However in the current system, "echo hello > /dev/ttyS0" command does not return at all! Also no characters appear on the destination port. I am running the echo command as root. The system boot messages show that the serial port in indeed /dev/ttyS0.

View 2 Replies View Related

Programming :: Pthread_create Does Not Return The PID ( Process ID)?

Aug 5, 2010

I am using pthread_create system call to create a thread. However pthread_create does not return the PID ( process ID). Is there any quick way to fınd the PID of the created thread.

View 1 Replies View Related

Programming :: Ofstream Return A Boolean In 'if (!ofs)'?

Mar 19, 2011

C++ code:
Code:
#include<fstream.h>

[code]....

View 4 Replies View Related

Programming :: Can't Understand Return Value Of Gawk?

Mar 10, 2010

I write a little script by bash.

#!/bin/bash
a=`gawk '/Iterations /{print $0}' hoge.log | gawk 'BEGIN{FS=" "}{print ($4)}'`
a=`expr 3 '*' $a`

[code]...

View 13 Replies View Related

Programming :: Prevent Echo As Return Value?

Jan 25, 2010

I have always encountered this problem in ubuntu bash shell scripts that echo command in a function will be treated as a return value when used in a function. e.g.

[code]...

The output would simply be xyz. Hence the echo seems to function as a "return" command when used in a function with a return value.

View 4 Replies View Related

Programming :: Does't Create Directory But Return As Value '0'?

Feb 23, 2010

$val = mkdir $directory, 755
print $val;
does't create directory but return as value '0'

[code]....

View 2 Replies View Related

Programming :: Pthreads Return Value Valid Or Not

Jun 14, 2010

I have confusion regarding pthreads return value. All in short, is the is a valid return value ?

[source]
void * myThrRoutine(void *arg)
{
struct myStruct **myst = (struct myStruct**) arg;
cout<<"In thread "<<(*myst)->var<<(*myst)->msg<<endl;
int x = 20;
pthread_exit((void*)x);
}
[/source]

This seems to work fine on pthread_join , but I want to ensure it is not by chance.

View 1 Replies View Related

Programming :: Python: Get The Return Value Of The Last Function?

Jun 13, 2010

But it's been hell finding an answer, or I just don't know what to look for..I have a prompt that asks for a float, and if the user doesn't put in a valid number, then it should die with an error message.

Code:
def die_with_error():
print 'ERROR: You didn't specify a valid number!'

[code]....

View 2 Replies View Related

Software :: Book Reader Program With Light Colored Smooth Background

Oct 22, 2010

I'm a big book lover so I read a lot. On windows I used Alreader for it's incredible handyness & it had a smooth lite brown background color. So it was easier for my eyes to read books in rtf, txt & so on formats instead of the default white background which is very annoying. Can you please suggest me a software like that for linux?

View 5 Replies View Related

Programming :: Init.d Script Does Not Return Prompt?

Jul 9, 2010

I have an a script in /etc/rc.d/init.d script that I would like to start and stop my sample application. I have named my script "foo", then I can start running my application my typing $ foo start but this does not return [OK] like other scripts do and does not return to shell prompt. My application is basically like this

int main()
{
do {
printf("Hi
");
sleep(1);
} while (1);
}

What is missing from my application that prevents from returning the shell prompt?

View 3 Replies View Related

Programming :: Pointer As Function Return Doubt?

Jul 15, 2010

I'm getting some information about C language and this session of a C book (follow the above link) is using a bad example for me. When I'm trying this example of function returning a pointer, my compiler is stating a warning that I return a pointer to a local variable. I realized that it is error prone after all this variable may be override before the function has done his execution. And the author is fooling me saying that this example is "perfectly safe". I'm wrong? There is something that I don't got yet? Sorry but this site is preventing me to post the link of book cause I'm a newbie, so a need the hack it. Just strip out the question signs:

{LINK}
?w?w?w
?cs.cf.ac.uk?

[code]....

View 6 Replies View Related

Programming :: Wrapping Around Functions With Different Return Types?

Feb 1, 2010

I have functions which return different data like: int, char*, double...

I also have a list of datatypes (INTEGER, TEXT, REAL...) which can be returned.

I need to map a datatype with function, which purpose is to return it. Therefore, when I determine a datatype, I would like to call the required function without doing switch all the time.

My idea is to have an array of structs like this:

Code:
struct type_func_map
{
int type;
void (*func_wrapper_int)(void); //void (*func_wrapper_text)(void); void (*func_wrapper_real)(void);
};

[Code].....

View 10 Replies View Related

Programming :: BASH Read File Once Then Return To Top?

Aug 8, 2010

I have a script that reads part of a line, delimited between the first and second intended part by a colon. Then it "chops" the part after the colon, which are words offset by commas (counting them beforehand so as to catch every word in the string's second part), like this:

Code:

"COLORS.JPG:red,orange,yellow,green,"
(Returning)
red

[code]....

single script that parses/breaks both parts of a line like this "COLORS.JPG:red,orange,yellow,green;blue,indigo,violet," so that the two parts, separated into single words (or two and three words, sometimes with spaces) can be used as single-line annotations and written to JPEG files using Exiv2. So far, I haven't been able to come up with a script that does this without one part of the total string(usually that part after the colon) becoming the first word in the second array. In other words, I look for this:

KEYWORDS:

[ ]red
[ ]orange
[ ]yellow

[code]....

Or vice-versa (ie, the second array winds up as a single-line "member" of the first). I think it's because I'm using a single while read loop to read the text file in which the filenames and substrings happen to be. If there's some way of reading a file once and going back to the beginning to read it again in another while loop, I haven't found it.

View 14 Replies View Related

Programming :: C Bool Return Values Conventions

Oct 30, 2010

I have a function that returns a boolean value, True of False. Is there any convention whether 0 = False or 0 = True? It should be obvious, 0=False, 1=True. However programs usually return 0 on success and reserve higher numbers for error values. I.e. if the program finishes successfully (function int main() finishes successfully ), it returns 0 - and that contradicts that 0 should be false.

And especially if I want a function to do some computations on parameters passed by reference and return success status. Should it return 1 (true) for success, or should it return 0 for success - like any Unix program does?

Is there any convention for this?

View 1 Replies View Related

Programming :: Detect Keypress Without Needing Return?

Oct 21, 2010

I'm witting a piece of code that needs to read key presses. However I cannot use them as stream, but rather need discrete reads. The code is to simulate an io board interface. So When I press say "d" I need to read it in instantly, not wait for return. I've tried sdl, but no luck (I'm reading in a thread and it causes some problems) I'm using linux so can't use conio.h functions, I've tired gatch from cureses but this still waits for return.So in C/c++ is there a way I can read instant key presses.

View 1 Replies View Related

Programming :: Get Process Statistics From Kernel And Return Them Buf?

Apr 7, 2011

I am want get next information: Get process statistics from kernel and return them buf as

Quote:

number of processes : ticks_user : ticks_system : ticks_interrupt : cpuseconds : procsizes : resident segment sizes I am find some this information in /proc/[pid]/stat, but there are is not data about ticks system, ticks_interrupt, cpusecond. Where I am can find it information???

I am write on C, better if it will file witch information, and not programm.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved