LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   ARGV[0] number or letters? & ranning script after finish previous program. (https://www.linuxquestions.org/questions/programming-9/argv%5B0%5D-number-or-letters-and-ranning-script-after-finish-previous-program-796839/)

DoME69 03-21-2010 07:44 AM

ARGV[0] number or letters? & ranning script after finish previous program.
 
Hi...

how can I recognize at perl if ARGV[0] is number or letters?

Quote:

#!/usr/local/bin/perl -w
use strict;

if (!defined($ARGV[0])) {
print "no value entered\n";
exit;
}
And another issue...

There is any way to ran script after previous program is finished?
Exmp: vi a ; script.file
"script.file" will ran only after "vi a" will finish his job


Thanks.

troop 03-21-2010 08:51 AM

Code:

if (!($ARGV[0] =~ m/^[A-z0-9]*$/)) {
print "incorrect value\n";
exit;
}

http://www.comptechdoc.org/os/linux/...gcommands.html

grail 03-21-2010 09:24 AM

Code:

$ARGV[0] =~ /^[+-]?\d+$/
This will work as long as checking integer numbers.

And if you put && between your line arguments one will wait to start after successful
termination of the previous command.

DoME69 03-21-2010 10:36 AM

Thanks both of you, it's work...

now my second problem...

http://www.comptechdoc.org/os/linux/...gcommands.html[/QUOTE]


This is not fit because, i want the second command will start after the first command will finish.

in this link both of commands are start / not start due errors.

grail 03-21-2010 10:59 AM

Hi dome69

I think you will need to explain more about what you require?
Are you saying that even if the first command (ie vi a) were to end with an
error that you would still want script.file (assuming this is an executable) to run??

DoME69 03-21-2010 11:19 AM

Hi grail...

Yes, even if the first command were to end with error.
but, i want the second command will start after the job of "vi a" will finish.

grail 03-21-2010 11:43 AM

In that case the semicolon ';' option will work. (IMHO it would seem not such a great idea to not test
the first command)

DoME69 03-21-2010 11:54 AM

Quote:

Originally Posted by grail (Post 3906620)
In that case the semicolon ';' option will work. (IMHO it would seem not such a great idea to not test
the first command)


I test it before i post.
the first command start the command1 and then the command2
but i want command2 will start after command1 will finish his job.

grail 03-21-2010 02:12 PM

Then you might want to give us more information about what commands you are running as this is not the normal
behaviour, unless the first command spawns into the background to continue.

DoME69 03-22-2010 01:29 AM

Hi...

The script i writing call to my phone.
but i want the script start after process is exit.

grail 03-22-2010 02:16 AM

Which process?
It seems odd as if it does not matter if the previous process finishes successfully or not
then it would appear they are unrelated and running one prior to the other is not important.

DoME69 03-22-2010 04:15 AM

This is not matter because i have process that ranning 1 - 8 hours maybe more and i want to know when it will finish.
after that i will debug if there was errors or not.

This is realy doesn't matter.

grail 03-22-2010 05:43 AM

1 Attachment(s)
Ok, I will take your word for it, but, this still does not help us if we do not know how your first command is running??

Let me try and use an example similar to your previous one:

example - vim dates.txt ; touch new_file

Expected results: vim will open dates.txt and the new_file will not be created until I close / exit vim (see attachment pdf for screenshots in order)

1. First screenshot is of terminal open with two tabs set to the same directory location and the above example set to run
2. After pressing enter, second screenshot shows terminal with vim viewing dates.txt
3. Third shows after moving to other tab in terminal and running ls in directory to show that new_file has not yet been created
4. Fourth shows back in original tab and having exited vim and running the ls command, now showing that new_file has been created only after previous program has ended

If your first command is headless or runs in the background we need to know otherwise I cannot see a away to assist you :(

DoME69 03-22-2010 06:29 AM

Quote:

Originally Posted by grail (Post 3907383)
Ok, I will take your word for it, but, this still does not help us if we do not know how your first command is running??

Let me try and use an example similar to your previous one:

example - vim dates.txt ; touch new_file

Expected results: vim will open dates.txt and the new_file will not be created until I close / exit vim (see attachment pdf for screenshots in order)

1. First screenshot is of terminal open with two tabs set to the same directory location and the above example set to run
2. After pressing enter, second screenshot shows terminal with vim viewing dates.txt
3. Third shows after moving to other tab in terminal and running ls in directory to show that new_file has not yet been created
4. Fourth shows back in original tab and having exited vim and running the ls command, now showing that new_file has been created only after previous program has ended

If your first command is headless or runs in the background we need to know otherwise I cannot see a away to assist you :(

I realy don'y understand while i'm running the first command the second start without waiting for the finish of the first.
how its can be that you ranning 2 commsnds separate by ";" and the second wait until the first one will finish.

lets test it...

gvim a ; gvim b

do you get both windows?
if you get both windows opens thats mean that the "gvim b" don't wait for the first command will finish.

what i want is after closing job "gvim a" the "gvim b" will start.

grail 03-22-2010 06:48 AM

I only have vim and not gvim but no, using

vim a; vimb

I get the a file opens and I can edit and so on and then as soon as I close it I am placed straight into
b file to edit.

Also, I did a ps ax | grep vim after hitting enter and then again after closing the first file.
Output is:

Code:

grail@wetworks:~/Documents/programming/bash$ ps ax | grep vim
13638 pts/0    S+    0:00 vim a
13658 pts/1    R+    0:00 grep --color=auto vim
grail@wetworks:~/Documents/programming/bash$ ps ax | grep vim
13659 pts/0    S+    0:00 vim b
13661 pts/1    S+    0:00 grep --color=auto vim

As you can see, clearly only one copy of vim running at a time.
What happens if you try the same?


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