How to run python function in Unix server using Excel VBA? -
How to run python function in Unix server using Excel VBA? -
i'd automate below steps using excel vba/vb script. here list of actions manually
step1: login winscp.
hostname: example.ash.pwj.com port: 22 usrname: xxx pwd: yyyy file protocol: sftptransfer file named 'testfile' local machine directory in unix server using winscp (the directory has python script 'connector.py')
step2: open putty.
destination host name: example.ash.pwj.com port: 22 connection type: ssh login using credentials.step3: phone call python script in directory. python connector.py argument1 argument2 argument3
example: python connector.py testfile example2.ash.pwj.com 123
i have handle winscp file transfer , calling python script in putty using excel vba/vbscript.
here code:
set sh = createobject("wscript.shell") sh.run "pscp -pw yyyy c:\users\abc\testfile xxx@example.ash.pwj.com:/home/test/dir", 0, true sh.run "plink.exe -pw yyyy xxx@example.ash.pwj.com python /home/test/dir/connector.py testfile example2.ash.pwj.com 514", 0, true
you shell out pscp
, plink
putty suite:
set sh = createobject("wscript.shell") sh.run "pscp -pw yyyy c:\testfile xxx@example.com:/some/dir/", 0, true sh.run "plink -pw yyyy xxx@example.com python /some/dir/connector.py arg1 arg2 arg3", 0, true
note need add together proper quoting if paths contain spaces.
if destination path destination directory without filename: specify path trailing filename. way you'll error when destination directory doesn't exist. otherwise pscp file user@example.com:/some/dir
might create file /some/dir
instead of /some/dir/file
when there no subdirectory dir
in /some
.
also, need create sure pass right path python script. when re-create file /home/test/dir/
should either alter directory before calling python script, or specify filename total path:
sh.run "plink.exe -pw yyyy xxx@example.ash.pwj.com python /home/test/dir/connector.py /home/test/dir/testfile example2.ash.pwj.com 514", 0, true
running python script /home/test/dir
doesn't automatically create directory current working directory.
python vba unix vbscript
Comments
Post a Comment