Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 cmdshell partly running

Author  Topic 

tigpot
Starting Member

6 Posts

Posted - 2008-09-04 : 13:58:50
I have a stored proc. that I call from a web page, with 3 parameters. The SP builds a string and writes a cmd line prompt that runs in xp cmdshell. This kicks off an application and builds a report. All of this works fine so far. After the report is generated I am using cmdshell to rename and separately move the document to a different folder with a unique name. The rename and move parts are not working. Its confusing to me since I must have rights to cmdshell since the first call to it works, but the second and third do not. Any reason for this? I looked around and didn't see anything, but do I have to 'close' the cmdshell before running it again, or clear it? Thanks for any help.

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2008-09-04 : 14:26:24
Can you describe what is happening when you try to invoke the command shell a second time and it fails? Any error message? Any error number?

=======================================
It is impossible to imagine Goethe or Beethoven being good at billiards or golf. -H.L. Mencken, writer, editor, and critic (1880-1956)
Go to Top of Page

tigpot
Starting Member

6 Posts

Posted - 2008-09-05 : 08:30:33
The SP is being called by a web page, so I don't see much when its running. All three of the instances where I call command shell are within the SP, I know the first one runs because the report gets generated (there are several factors on the erport that I can see to verify that its running when I call it). The other two instances just rename and then move the file, which I can also see is not getting done. The SP finishes though, and returns control to the webpage. Is there something I can look for in the SQL logs?
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2008-09-05 : 09:18:42
is there a timing difference here....why aren't all the cmdshell commands done in one go?

could it be that things are executing asynchronously? i.e. cmdshell #1 isn't finished before #2 + #3 start.
Go to Top of Page

tigpot
Starting Member

6 Posts

Posted - 2008-09-05 : 14:56:24
I suppose they aren't done together because I didn't know I could do them that way. I assumed that each was finished before the next ran since the second and third are called after the first. In a stored procedure would the second call start before the first was finished?
Go to Top of Page

tigpot
Starting Member

6 Posts

Posted - 2008-09-10 : 10:18:18
Are there any processes I should check to see if cmdshell is still running or not getting closed all the way?
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2008-09-11 : 05:19:12
in cmdshell #1...create a marker file at the start and delete same at the end.
in cmdshell #2...test for the presence of the marker file...if it's there....then #1 is still running or has failed before deletion.
Go to Top of Page

tigpot
Starting Member

6 Posts

Posted - 2008-09-18 : 09:40:25
Thanks for the suggestions, I will try that next. I was wondering about something else while I was looking at the SP today. If I check for the return code each time I call cmdshell, wouldn't that tell me if the process was finished?
Go to Top of Page
   

- Advertisement -