LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-21-2010, 07:44 AM   #1
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Rep: Reputation: 16
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.

Last edited by DoME69; 03-21-2010 at 08:24 AM.
 
Old 03-21-2010, 08:51 AM   #2
troop
Member
 
Registered: Feb 2010
Distribution: gentoo, arch, fedora, freebsd
Posts: 379

Rep: Reputation: 97
Code:
if (!($ARGV[0] =~ m/^[A-z0-9]*$/)) {
print "incorrect value\n";
exit;
}
http://www.comptechdoc.org/os/linux/...gcommands.html

Last edited by troop; 03-21-2010 at 08:54 AM.
 
Old 03-21-2010, 09:24 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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.
 
Old 03-21-2010, 10:36 AM   #4
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Original Poster
Rep: Reputation: 16
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.
 
Old 03-21-2010, 10:59 AM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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??
 
Old 03-21-2010, 11:19 AM   #6
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Original Poster
Rep: Reputation: 16
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.
 
Old 03-21-2010, 11:43 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
In that case the semicolon ';' option will work. (IMHO it would seem not such a great idea to not test
the first command)
 
Old 03-21-2010, 11:54 AM   #8
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by grail View Post
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.
 
Old 03-21-2010, 02:12 PM   #9
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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.
 
Old 03-22-2010, 01:29 AM   #10
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Original Poster
Rep: Reputation: 16
Hi...

The script i writing call to my phone.
but i want the script start after process is exit.
 
Old 03-22-2010, 02:16 AM   #11
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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.
 
Old 03-22-2010, 04:15 AM   #12
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Original Poster
Rep: Reputation: 16
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.
 
Old 03-22-2010, 05:43 AM   #13
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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
Attached Files
File Type: pdf sceenshots.pdf (149.5 KB, 4 views)
 
Old 03-22-2010, 06:29 AM   #14
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by grail View Post
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.
 
Old 03-22-2010, 06:48 AM   #15
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scope of $ARGV[0] in perl ShaqDiesel Programming 3 10-11-2009 07:15 AM
Set up Grub to define drive letters Nishtya Linux - General 2 02-05-2009 06:11 PM
Capital 1st letters in Perl resetreset Programming 3 08-21-2008 01:41 PM
define Primary number or not... dicksonmakts Programming 9 04-04-2006 11:04 PM
Wine problem- cannot define drive letters minister_fister Linux - Software 1 10-01-2003 01:21 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration