469,275 Members | 1,852 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

system command not waiting

Ok so ive reached the end of my knowledge and have tried to find out how to do it and just plain dont understand it.

I have a system call:
Expand|Select|Wrap|Line Numbers
  1. system("db2cmd.exe \"db2 connect to vop9 user joebloggs using joesPassword&&db2 LOAD FROM \"d:\\vop9\\records_test.csv\" OF DEL MODIFIED BY COLDEL; METHOD P (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17) MESSAGES \"D:\\vop9\\output.txt\" INSERT INTO UKVOICE.CALLDATA (ID, REFERENCE, RECORDTYPE, NASIP, TIMESTAMP, USERNAME, SOURCEID, DESTUSERNAME, DESTINATIONID, SGWIP, DGWIP, H323SETUPTIME, H323CONNECTTIME, H323DISCONNECTTIME, CONNTIME, DISCONNTIME, DURATION) NONRECOVERABLE INDEXING MODE AUTOSELECT&&db2 connect reset&&exit\"\n")
  2.  
It calls a DB2 command window: "db2cmd.exe" with parameters to connect to a DB and then load data from a .csv file reset the DB connection and exit the DB2 command window. This takes some time.

I then need it to move the csv to another location. I am currently using a simple system command:
system("move xyz.csv folder1");

However my perl script opens the DB2 part and then leaves it to run then goes straight onto executing the move command. Before you know it, the file is moved and is no longer there for the data to be transfered to the database.

Can anyone enlighten me as to how to wait for the system first system command to complete before moving onto the next one?

James
Aug 31 '07 #1
8 9978
numberwhun
3,503 Expert Mod 2GB
Welcome to TSDN James!

First, I cleaned up your post a touch by adding code tags around your...well....code. Whenever you post code, enclose it in code tags. The example of the tags is on the right of your Message window in the REPLY GUIDELINES box. if you set the initial code tage to be code=perl, enclosed in square brackets, then the forum will syntax highlight your code for Perl.

Second, if you could post your code here (more than just the system command), then we will be able to look at your script and see what is going on.

Thanks!

Jeff
Aug 31 '07 #2
KevinADC
4,059 Expert 2GB
well lookee here:

numberwhun
Moderator

you have my sympathies Jeff ;)
Sep 1 '07 #3
numberwhun
3,503 Expert Mod 2GB
well lookee here:

numberwhun
Moderator

you have my sympathies Jeff ;)
Yes, yes, Thank you! Actually, I am quite please with it and am enjoying being able to help out more. Although, the sympathies are still accepted for when I am having rough days. ;-|)

Jeff
Sep 1 '07 #4
KevinADC
4,059 Expert 2GB
Yes, yes, Thank you! Actually, I am quite please with it and am enjoying being able to help out more. Although, the sympathies are still accepted for when I am having rough days. ;-|)

Jeff

In all seriousness, I thought you would be a good forum moderator and I guess the staff of this forum was waiting for you to get your post count up to invite you to be one. Maybe not, I have not heard anything from Mary or any of the other staff. Maybe they have just been busy. I am sure Miller will appreciate the company. Keeping the unwashed masses in line is a constant struggle. ;)

Enjoy moderating and congratulations.

-Kevin

PS: you still have my most sympathetic sympathies :)
Sep 1 '07 #5
numberwhun
3,503 Expert Mod 2GB
Actually, I approached Miller via PM a couple of weeks ago. He has been busy and unable to get to many things, but he was able to put the request in the other day and voila, a birthday present for me. :-)

I will enjoy it, and thanks!

Jeff
Sep 1 '07 #6
miller
1,089 Expert 1GB
Can anyone enlighten me as to how to wait for the system first system command to complete before moving onto the next one?
James,

The system command is a blocking operation, so it will automatically wait until the child process i completed. This means that your first command most likely is not working correctly, and that is the source of your problem.

I suggest that you clean up your code a little by using qq{} as your string delimiter instead of "". This would prevent the need to escape all of double quotes. Additionally, since you have no variables that need to be interpolated, it would probably be even better to use q{} instead.

Just note that creating a system command that uses parameters can be complicated since the escaping can be tricky. You must escape things on the perl level, and also on the system level.

- Miller
Sep 3 '07 #7
docdiesel
297 Expert 100+
Hi there,

afaik this is a DB2 item and not perl related:
Expand|Select|Wrap|Line Numbers
  1. system("db2cmd.exe \"db2 connect to vop9 ...
db2cmd spawns off and starts running in a separat address space, so that the system() call returns.

Regards, Bernd
Sep 3 '07 #8
docdiesel
297 Expert 100+
Hi again,

usually I'm working on Linux systems and am using bash shell scripts, but something like this could work with perl on Window$, too (in very rough perl code):

Expand|Select|Wrap|Line Numbers
  1. open(  MYPIPE, " | db2cmd.exe ");  # (pipe to db2cmd.exe) for output
  2. print MYPIPE "
  3.   db2 connect to mydb
  4.   db2 load from ...
  5.   db2 connect reset ";
  6. close(MYPIPE);
  7.  
Maybe you've got to use the "db2" command instead of db2cmd.

Regards, Bernd
Sep 3 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Allan Adler | last post: by
6 posts views Thread by Hugh Janus | last post: by
5 posts views Thread by =?Utf-8?B?Z215ZXJz?= | last post: by
3 posts views Thread by pavi | last post: by
5 posts views Thread by Saya | last post: by
12 posts views Thread by tom_kuehnert | last post: by
9 posts views Thread by =?Utf-8?B?UGF1bCBQb2xpY2FycA==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.