Login | |
|
 |
RE: how to wait until an application finish some proces... - 2/8/2006 8:49:11 AM
|
|
 |
|
| |
Cybex
Posts: 412
Score: 0
Joined: 9/14/2005
From: Florida
Status: offline
|
Post what you have so we can see what and how you are making your calls in order for us to give you the correct guidance. Cybex
_____________________________
Common sense is not so common.
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 2/9/2006 1:12:41 AM
|
|
 |
|
| |
armbp1972
Posts: 11
Score: 0
Joined: 2/8/2006
Status: offline
|
I can't post exactly what I'm doing right now because I'm doing that proyect at home, and now I'm at work but is something like this: Set Objeto_Shell = WScript.CreateObject("WScript.Shell") Cod_Retorno = Objeto_Shell.Run("C:\Sound\Forge32.exe", 1 , False) Objeto_Shell.AppActivate ("Sound Forge 4.5") for i = 1 to 1000000 'I know this isn't the best way to insert time waits but for the purpouse right now it works :-D i = i +1 next Objeto_Shell.SendKeys "^O" 'This is for opening a file in Sound forge Objeto_Shell.SendKeys "archivo.wav" Objeto_Shell.SendKeys "~" for i = 1 to 1000000 'I have to repeat the cycle here because Sound Forge take it's time to open the file, i = i +1 'If I send the next commands without waiting Sound Forge ignore them next Objeto_Shell.SendKeys"%PN" 'The proccessing command And so on.... As far as I knows sound forge exposes no API at all, but I guess that some other trick can be used. One way could be based in the fact that the proccesing of the sound data is very processor intensive, so I can sense the use of the processor by some way and wait until it falls below some threshold. How can I access that data? Other way could be is sound forge, as a windows program send some kind of messages to windows when it start or finish to do something( meaning "don't bother me, I'm working now", or "I've finished you can send me messages again"), I've not real knowledge about windows messages, just some background about what they are, but maybe there are something like that.
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 2/9/2006 2:24:39 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
|
With no exposed API, there will be no good solution. You could look at the cpu usage for that process. You would get that through WMI. Search this forum for WMI and you will find lots of examples. As for intercepting any semaphores between the app and the OS, I wouldn't even know where to start but I could almost guarantee it would not be possible in VBScript. I would expect that sort of functionality to be well outside the intended scope of a scripting language like VBS.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 2/9/2006 2:59:02 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
|
What version of Sound Forge are you using? I've never used it, but some versions appear to provide hosted automation from within the program. One of the hosted languages is VBScript. THat would be the best solution if it is available in your version.
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 2/9/2006 5:18:07 AM
|
|
 |
|
| |
armbp1972
Posts: 11
Score: 0
Joined: 2/8/2006
Status: offline
|
The Sound Forge version is 4.5. The problem is that it does not support all kind of mp3s. There are some of them that SF can not open, even if I change de codec. So I ended using winamp to convert the mp3 to wav, then open the last one in SF. Now, winamp insert some caracters (001_etc...) in the file name it give as output in wav format (no matter what options you activate or deactivate in it's configuration), resulting in that I need to restore the file name to it's original after making all the processing in SF. That's why I decided to use an external script, besides de fact that I don't want to overwrite the originals, in case some error occur, ending this in that I have to replicate the folders extructure. Any way, just a few minutes ago I finished, succesfully, a test with some code I downloaded from MSDN that keeps a record of one process processor time. Originally it is for the idle time but I test it with some other processes and the results are satisfactory. So I will adapt it to my needs tonight at home, and I will post the results.
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 3/2/2006 6:36:59 AM
|
|
 |
|
| |
armbp1972
Posts: 11
Score: 0
Joined: 2/8/2006
Status: offline
|
Hi, continuing with my proyect I solved the problem of waiting for the sound forge, and the winamp too, to finish the processing I want they do on the files. I used WMI to monitor the use of the CPU, in sound forge, and the bytes written to disk, in the case of winamp. I did a procedure that waits until the variable I'm monitoring stay at 0 by certain amount of time (actually 5 seconds) and then continue the following instruccions, its something like this: - instruct the sound forge to do the processing (very CPU intensive) - call the procedure that waits until the processor time of the sound forge process stay at 0 for 5 seconds - continue the execution of the following instrucctions The procedure is the same for the two programs, what change is the performance counter I monitor, which I send as a parameter, along with others like the time I want to wait, etc.. making it suitable for use in other situations. I having problems now with the filesystemobject object. When I try to use it to access a file, there is no way I can get it with the long name, It give me some error when I do it. I mean: I'm getting the folder structure for the folder where I have all my mp3s, recreate that structure in other place, because I don't want to overwrite the mp3, nor the original folder, in case something goes wrong. With each file I send it to the winamp to create a new one but in wav format, in this case I want that the resulting file be written to the new folder ( i.e. if the original mp3 was "D:\Musica\AirSupply\track01.mp3" I want the wav file be written as "E:\Musica\AirSupply\track01.wav". The problem is that the winamp includes some caracters in the output wav file, if the original is named "track01.mp3" the output file it give is "001_track01.wav", and there is no way I can find how to disable that annoying behavior. So my solution is to recreate the original name inside the script before writting it to disk, but when I try to use the file.name property of the file object of the filesystemobject, every time I get a file with a name longer that 8 caracters it give me an error. If the name is short, there is no problem. Of course, some of you are going to ask me to post what I'm doing to analize it, I will do it tomorrow, because that proyect I'm doing it at home and have no code in here( my work place), but I post this now in case that's a known problem.
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 3/3/2006 2:22:28 AM
|
|
 |
|
| |
Country73
Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
|
Depending on how you have your script coded to search for the new wav file created, you may be able to use the InStr to grab the correct wav file. You're saying that when you create the wav file from an mp3, and that it can have additional characters at the beginning of the name; Example: track01.mp3 -> 001_track01.wav, 005_track01.wav, etc... When you are searching through the folder that contains the new wav files you can use the InStr function. This example will move all files with a wav extension to one spot, a little configuring can be done to move specific wav files to an exact location. (I'm useing oFS for the variable of "CreateObject("Scripting.FileSystemObject")) Set g = oFS.GetFolder(<path to where the wav files are stored>) Set f = g.Files For Each f1 in f If InStr(f1.Name,".wav")Then oFS.MoveFile f1, <new Location> End If Next
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 3/3/2006 6:15:08 AM
|
|
 |
|
| |
armbp1972
Posts: 11
Score: 0
Joined: 2/8/2006
Status: offline
|
That's not the point, here is what I have done: This is a sub that I call passing as parameter the name of the folder I want to process '*************************************************************************************************************************************** Sub Folder_structure(Name) Set carpeta = fso.GetFolder(Name) 'this asign to the variable "carpeta" the folder object in question fso.CreateFolder("E:\" & Right(carpeta.path,Len(carpeta.path)-3)) 'this duplicate the folder structure in the E: disk, a diferent one from where the original folder is Set files_colection = carpeta.Files 'asign to the variable files_colection the files inside the folder in question for each A in files_colection 'this cycle applies to every individual file inside the folder If LCase(Right(A.Name,3)) = "mp3" then 'if last 3 characters of the file name are equal to "mp3", i.e: with this I assure that only those files (mp3s) are proccesed loShell.Run A.Shortpath, 1 , false ' loShell is the variable that has been assigned the shell object outside the sub with the instruction: Set loShell = CreateObject("WScript.Shell") ' so running the name of the file in windows makes winamp, the registered program for that kind of file to play it. This is one of the situations ' where I had to use the shortpath, because using the name, if it's longer that 8 characters, it give an error that "can't find the file". ' previously winamp has been configured to give it's resultant wav file in a folder named "E:\Tempo", this is going to be important some lines ' below, remember that the winamp append 00x_ to the begining of the file name this way: track01.mp3 -> 001_track01.wav Wscript.sleep 2000 Call wait("winamp",1,1000,5) ' this procedure waits until some performance counter ( in this case bytes written by seconds of the process winamp) remains at 0 for 5 seconds; ' as what the winamp is doing is writting a wav file to disk, as long as it has not finished the performance counter is very high fso.CopyFile "E:\Tempo\*" & Left(A.Name,Len(A.Name)-4) & ".wav", "E:\Tempo\" & Left(A.Name,Len(A.Name)-4) & ".wav",true 'here is where the problem gets worst, because there 'there is no way I can do it work, supposedly it should ', in fact it does if the name is short ( e.g: 1.mp3), 'but is the name is longer that 8 characters, forget about it ' "file not found" is the result 'from this point on, the procedure call the sound forge to fix the renamed file 'convert it with other program to mp3 'move it to the destination folder ( the previously created in the second line of the script) 'erase all temporal files created 'and continue the sub with the following code that looks for inside the subfolders End if Next Set files_collection = Nothing Set folders_collection = carpeta.SubFolders For Each C in folders_collection Call Folder_structure(C.Path) Next Set folders_collection = Nothing Set carpeta = Nothing End Sub '******************************************************************* I'm sure that everything else in the sub works, but the CopyFile instuction. I've done some tests with msgbox, etc.. and nothing, the conclusion is that the wshell object does not support the use of long files names, something that is absurd, I think, iin a component of windows XP service pack 2, the OS I'm using. So, there is something wrong with my code, something missing I guess. In order to give more reference here is the code before calling the sub: Public fso, MyFile, loShell, oExec Set fso = CreateObject("Scripting.FileSystemObject") fso.CreateFolder("E:\Tempo") fso.CreateFolder("E:\Tempo\Salida") Set loShell = CreateObject("WScript.Shell") Call Winamp_Ini("WAV Writing Output Driver","config_waveoutdir","E:\Tempo") Call Winamp_Ini("Winamp","outname","out_disk.dll") set oExec = loShell.Exec("C:\Program Files\Winamp\winamp.exe") Call Folder_structure("D:\Musica") The Winamp_Ini sub change some parameter in the winamp.ini file. They are, in the order given: section, parameter, new value. The first call to the sub sets the output directory fo the wav output driver to E:\Tempo, the second one set the output driver of the winamp to the disk writer plugin. After the folder_structure sub has finish I reset the output driver of the winamp to the direct sound driver. This part can be reworked to be more safe, but that's not an issue now.
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 3/3/2006 6:42:48 AM
|
|
 |
|
| |
ebgreen
Posts: 5069
Score: 31
Joined: 7/12/2005
Status: offline
|
Straight from the WSH docs for .CopyFile: quote:
Wildcard characters can only be used in the last path component of the source argument. So, this is not valid: so.CopyFile "E:\Tempo\*" & Left(A.Name,Len(A.Name)-4) & ".wav", "E:\Tempo\" & Left(A.Name,Len(A.Name)-4) & ".wav",true
< Message edited by ebgreen -- 3/3/2006 7:22:51 AM >
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 3/3/2006 7:07:52 AM
|
|
 |
|
| |
Country73
Posts: 733
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
|
So for this line here: fso.CopyFile "E:\Tempo\*" & Left(A.Name,Len(A.Name)-4) & ".wav", "E:\Tempo\" & Left(A.Name,Len(A.Name)-4) & ".wav",true I'm assuming the the "*" in "E:\Tempo\*" is supposed to grab each file name and see if it end in ".wav" ? By what I had supplied earlier, you could do what you want. You may need to add a little more coding for it if you are actually pulling the .wav files out of a seperate folders inside of "E:\Tempo" Also, I used the FileMove method instead of FileCopy, but by changing to FileCopy will work also. You can then add the ",True" to the end of the FileCopy line.
< Message edited by Country73 -- 3/3/2006 7:10:01 AM >
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 3/3/2006 8:14:25 AM
|
|
 |
|
| |
armbp1972
Posts: 11
Score: 0
Joined: 2/8/2006
Status: offline
|
ebgreen: when I read that restriction in the wsh documentation I understood it as that the "last path component of the source argument" is the file name (or the last folder in the chain, if no file name is supplied). So, that's exactly where I'm using it. I didn't understand it as the last part of the last path component. Here the documentation is not so clear, I'm going to do some tests in order to get some clarity. Country73: yes, the * is what you mean: A.Name = track01.mp3 'the original mp3 file name Len(A.Name) = 11 characters 11 - 4 = 7 'very obvious :- D Left(A.Name, 7) = track01 "E:\Tempo\*" & track01 & ".wav" = *track01.wav it's suppose to work, I guess, unless ebgreen is right. I'm going to give it a little thought to your suggestion but I don't see how I'm going to guarantee that the new file will have the same name as the original mp3. Remember that I have to strip out the 00x_ that winamp append to the begining of the file name. Your sugestion is very good to simplify the work in the script, in fact I'm already thinking in changing the way it works, not file by file but all the files in the folder at a time with your way, but I don't see how it can help me to restore the original file name. I can not assume that the winamp will always append xxx_ to the begining of the file name, maybe it does xxxx_ if the folder has more than 1000 files, and so on. Alright that's a very unprobable case, in fact I really doubt that in my collection of mp3s that happens, but I'm trying to code the more general as posible, it's right way, no? That's why I used that construction," E:\Tempo\*" & Left(A.Name,Len(A.Name)-4) & ".wav ". Whatever if before, plus the name of the original file minus the last 4 characters, plus .wav, which I know it's going to be the extension of the file I want to rename.
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 3/3/2006 11:05:24 AM
|
|
 |
|
| |
Fredledingue
Posts: 383
Score: 0
Joined: 5/9/2005
From:
Status: offline
|
Install AutoItX. It add advanced features to control/read windows title, text messages, move the mouse etc. It's radical. http://www.autoitscript.com/autoit3/files/beta/autoitx/ Download AutoItX.chm 07-Aug-2005 10:18 158k AutoItX3.dll 07-Aug-2005 10:18 85k Note: you need to register the dll. If you don't know how please ask.
< Message edited by Fredledingue -- 3/3/2006 11:08:03 AM >
_____________________________
Fred
|
|
| |
|
|
|
 |
RE: how to wait until an application finish some proces... - 3/6/2006 5:50:37 AM
|
|
 |
|
| |
armbp1972
Posts: 11
Score: 0
Joined: 2/8/2006
Status: offline
|
Country73: I finished the script with a slight variation of your method, in fact I didn't use instr() at all, I just asigned the E:\Tempo folder to an object variable through fso.getfolder, created a file collection object with the files in E:\Tempo, where there will only be a file (the wav I need to strip out the xxx_ inserted by winamp) and accessed it using a "for each f1 in f", been f the file collection. this is a little overprogrammed, I think, because there will be only one item in the collection, so I don't need a "for each..." cycle but I could not use the item property of the file collection object, I don't know why. It's suppose that work this way: fso.move file f.item(key), etc... where "key" should be an index no? well, I used 0, 1, "0", "1", and every time there was an error. I was guessing that, as there is only one file in the folder the key should be 0 or 1. If someone has a suggestion, welcomed will be. Any way, using the "for each f1 in f" worked fine. So I set everything else up, finished the details, clean up the E: disk for it to have all the capacity available for the work, and made a test with a few ( 2 or 3) folders with mp3s. Everything was working fine until the sound forge misunderstood some key the script send it and I have to end the whole proccess with task manager. A few tests followed inserting sleeps, an so on, and the conclusion is that using sendkey to command a program to do some things like open files, running commands, etc.. is prone to fail in some point. I didn't find it really, because the failure could arise in any point or in any time, even 1 hour after everything was working fine. I suspect that maybe it's related with how long it's the string the script send as the name of the file to open, I will do some tests tonight, just to be sure. But the suggestion of the friend Fredledingue of using autoItX looks very promising, I downloaded it and installed, and seems like you can do everything to a windows program with it. By the way, the package I installed seems to do everything for me, what about the registration of the dll you talk about? I didn't downloaded from the site you suggested but from the home web page.
|
|
| |
|
|
|
|