PDA

View Full Version : [SLEEPER:] VBA-PERL via .bat



kroz
07-12-2012, 06:50 AM
Hey guys,

I have a strange occurence when i'm running a .bat file from VBA (with shell)

I create a .bat file from vba and one of the lines calls a perl procedure with some variables.
The problem is this: when i run this batch file from inside vba it doesn't do what it should. When i run the same batch file directly it works!

I have no idea why or where to look for the error.

Thanx for the help

Kenneth Hobs
07-12-2012, 07:54 AM
We don't know what "doesn't do what it should" means. You will have to post code if you want to clarify what is going on or explain in more detail.

Sometimes, it is a matter of timing when you shell and need to wait for a process to complete. You may need a ShellWait() instead.

kroz
07-12-2012, 08:11 AM
The perl is listing the items from a special access space, a sort of "show me what you have on that server"

the content of the file is:


set submit_Multisite=QY
PerlPath\myperl.pl ry ls | find "-" > MyPath\myfile.txt

that's it.

When i run the .bat directly i get a correct listing. When i run it with my macro myfile.txt remains empty.

Kenneth Hobs
07-12-2012, 08:22 AM
As I explained, try ShellWait(). Using that method, you may not even need to run the BAT file though you can if you like. http://www.vbaexpress.com/forum/showthread.php?t=34604

kroz
07-12-2012, 11:05 PM
Hey Kenneth

Thank you for the help. Unfortunately, even with ShellandWait() it didn't work. It appears to be processing the command but the result file is empty.

I'll keep trying

By the way, i should have seen that it would not work - i wasn't fully running the macro yet - i'm still in the step into phase. So i'm taking it line by line and it doesn't populate the file.

snb
07-13-2012, 12:39 AM
Why writing to a file if you can get the result in a variable ?



sub snb()
c01=createobject("wscript.shell").exec("cmd /c PerlPath\myperl.pl ry ls | find -").stdout.readall
end sub

kroz
07-13-2012, 12:42 AM
i'm writing to a file because i have to process the info afterwards (as in obtain a clean list of the files and add a command before each file name)

And i'm using a "set var=value" that shell errored out - file not found

kroz
07-13-2012, 02:22 AM
I think I've located the problem! The server info i get from my perl needs a userid, because the info returned is different for each user.

The solution might be to use runas + sendkeys.. i'll keep digging