Visit Our UNIX and Linux User Community


PERL: wait for process to complete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting PERL: wait for process to complete
# 1  
Old 04-16-2004
PERL: wait for process to complete

I'm using PERL on windows NT to try to run an extract of data. I have multiple zip files in multiple locations. I am extracting "*.t" from zip files and subsequently adding that file to one zip file so when the script is complete I should have one zip file with a whole bunch of ".t" files in it.

The problem comes after I extract the ".t" file and try to zip it up again, the file is not yet in the directory so zip cannot find the file. I have commented out the code beneath the zip command while testing the program.
Please help!

Code:
###Get generation directory information ###
open(GENDIR, "<gens.txt") or die "Can't open gens.txt $!";
while(<GENDIR>){
	chop($_);
	push(@gendirs,$_)
}	

## Unzip .t file into stage directory ##
for $i (0 .. $#gendirs){  
   	($gennum)=(split /\\G/, $gendirs[$i])[1];
	#print "$gennum\n";
	print "unzip -d \\stage -j $gendirs[$i]\\*.zip *.t\n";
	system("unzip -d \\stage -j $gendirs[$i]\\*.zip *.t");
##zip .t file ##
	system("zip -v -9 \\stage\\vista.zip ${gennum}.t");
	#open(GENS, "<listofGens.dat") or die "Can't open listofGens.dat $!";
	#while(<GENS>){
		#chop($_);
		#if ($_=~/^$gennum\|/){
			#($repname)=(split /\|/)[1];
			#print "$repname\n";
			#print "${gennum}.t";
			#print "\nrename \\stage\\${gennum}.t \\stage\\$repname\n";
			#system("rename stage\\${gennum}.t stage\\$repname");
			#last;
		#} 
		
	#}
	#close(GENS);
}





#open(GENS, "<listofGens.dat") or die "Can't open listofGens.dat $!";
#while(<GENS>){
#}

# 2  
Old 04-19-2004
i have to ask a couple of questions.

1) if you comment out the zip portion do you see the files extracted to the proper directory?

2) why are you trying to zip it back up right after you unzip it? why dont you do all of your unziping then call your zip processes.

3) altho i havent worked with perl on windows i dont think you need to backslash the backslash in this case.

but at this point i would be makeing sure each portion of the script is doing what you want.

start w/ the unzip functions and makesure it is extracting your data to the correct directory.

then work on the zip portion. persaonly i would write 2 functions.

1 that unzips and 1 that zips; and i would do all the unziping first then do the zip.
# 3  
Old 04-21-2004
Thanks for the response. I've figured out the problem, which is not what I thought it was. The issue is that I did not specify the correct directory when zipping the files and thats why the zip program was complaining.

so...

Code:
system("zip -v -9 \\stage\\vista.zip ${gennum}.t");

should have been
Code:
system("zip -v -9 \\stage\\vista.zip \\stage\\${gennum}.t");

To answer your questions Optimus ( thanks for your suggestions which led me to the problem)...
1) Yes the files were extracted to the directory.
2) This method of zipping the files immediately after unzipping them is purely a space issue. I am dealing with thousands of text files, many of them are around .5GB unzipped. If I were to unzip all of them I would run out of disk space.
3) In my experience with windows and perl, you need either the double backslash or forward slash. There may be other ways to do it that I am not aware of.

Previous Thread | Next Thread
Test Your Knowledge in Computers #353
Difficulty: Medium
mawk is a very fast AWK implementation by Mike Brennan based on a Python interpreter.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script parallel tasks and command to wait untill complete?

Hello, im having bash script with while *** command1 && command2 && command3 && done i want to ask how i can prevent overloading server, by waiting untill all commands complete? any low resources intensive command like "wait" - i dont know if exist? (2 Replies)
Discussion started by: postcd
2 Replies

2. Shell Programming and Scripting

In Shell Script Does Second Command Wait For First Command To Complete

Hi All, I have a question related to Shell scripting. In my shell script, I have following two commands in sequence: sed 's/^/grep "^120" /g' $ORIGCHARGEDAMTLIST|sed "s;$;| cut -f$FIELD_NO1 -d '|' | awk '{ sum+=\$1} END {printf (\"%0.2f\\\n\", sum/100)}' >$TEMPFILE mv $TEMPFILE $ORIGFILE... (3 Replies)
Discussion started by: angshuman
3 Replies

3. Shell Programming and Scripting

Wait for one processes to complete in a shell script

Let's say I start process A.sh, then start process B.sh. I call both of them in my C.sh How can I make sure that B starts its execution only after A.sh finishes. I have to do this in loop.Execution time of A.sh may vary everytime. It is a parameterized script. (17 Replies)
Discussion started by: rafa_fed2
17 Replies

4. UNIX for Dummies Questions & Answers

How do you wait for command substitution processes to complete?

When running a command using the >(cmd) syntax in bash how do you wait for the command to complete before moving on in your script? Here is a simple example: zcat largefile.gz | tee >(wc && echo “HELLO”) > /dev/null # I tried wait, here but it doesn't wait for the process in the subshell.... (8 Replies)
Discussion started by: mrvwman
8 Replies

5. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

6. Filesystems, Disks and Memory

hdparm + HDIO_DRIVE_CMD(null) (wait for flush complete) failed: Inappropriate ioctl

Hi All, Am finding performance of my SD card using hdparm. hdparm -tT /dev/BlockDev0 /dev/BlockDev0: Timing cached reads: 1118 MB in 2.00 seconds = 558.61 MB/sec HDIO_DRIVE_CMD(null) (wait for flush complete) failed: Inappropriate ioctl for device Timing buffered disk reads: 14... (0 Replies)
Discussion started by: amio
0 Replies

7. UNIX for Advanced & Expert Users

wait process

can any one please give me clear idea of wait process in UNIX system. I am using AIX 5.3 and see loots of wait process. I have very basic concept of wait process. If CPU has nothing to do then a wait process is generated per CPU. But i want know the detail how is it forked. Is wait a jombe... (2 Replies)
Discussion started by: pchangba1
2 Replies

8. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

9. Shell Programming and Scripting

Wait for Background Process to complete

I am attempting within a for-loop, to have my shell script (Solaris v8 ksh) wait until a copy file command to complete before continueing. The specific code is: for files in $(<inputfile.lst) do mv directory/$files directory/$files ksh -m -i bg %% wait $! done I am shaky on the... (3 Replies)
Discussion started by: gozer13
3 Replies

10. UNIX for Dummies Questions & Answers

Process Wait on DG UX

Does anyone know what the equivalent command to pwait on Solaris is on DG/UX. I need my script to kick off a process and wait till it is complete before continuing with the script. (4 Replies)
Discussion started by: fabbas
4 Replies

Featured Tech Videos