Hi Guys im trying to excute a cmd line from VBA but it keeps giveing me errors like "c:\program" is not reconised. ive been stuck here for hours adding Chr(34) and other things but still no luck.
here is my code
Path = """C:\Users\Phill\Desktop\Mortgage Illustration 211206142739.pdf"""
scommand = """C:\Program Files (x86)\A-PDF Data Extractor\PRCMD.exe""" & _
Path
Shell "cmd.exe /k " & scommand, vbNormalFocus
Maybe something like this:
Dim exe, pth
exe = "C:\Program Files (x86)\A-PDF Data Extractor\PRCMD.exe"
pth = "C:\Users\Phill\Desktop\Mortgage Illustration 211206142739.pdf"
Shell "cmd.exe /k """"" & exe & """ """ & pth & """""", vbNormalFocus
EDIT: fixed - the whole command (exe plus path) also needs to be quoted...
Related
I'm trying to automate image uploading to Instagram using Selenium in Python. I'm successful till opening the fileDialogue but I'm not able to change the directory to where the image is located. It returns an error that ToolbarWindow32 can't be detected by AutoIt.
My code:
ActionChains(browser).move_to_element(browser.find_element_by_xpath(
"/html/body/div[8]/div[2]/div/div/div/div[2]/div[1]/div/div/div[2]/div/button")).click().perform()
handle = f"[CLASS:#32770; TITLE:Open]"
autoit.win_wait(handle, 60)
autoit.control_set_text(handle, "ToolbarWindow32", photopath) # This line give me the Error
autoit.control_set_text(handle, "Edit1", photopath)
autoit.control_click(handle, "Button1")
Take a look how this is done in _WD_SelectFiles with: https://github.com/Danp2/au3WebDriver/blob/master/wd_helper.au3
You should be able to do the same directly with python+selenium without using AutoIt.
Also take a look on:
https://github.com/Danp2/au3WebDriver/blob/master/wd_demo.au3
There is example how directly in AutoIt it is possible to do the same with WebDriver UDF without opening any FileOpenDialog :
Func DemoUpload()
; REMARK This example uses PNG files created in DemoWindows
; navigate to "file storing" website
_WD_Navigate($sSession, "https://www.htmlquick.com/reference/tags/input-file.html")
; select single file
_WD_SelectFiles($sSession, $_WD_LOCATOR_ByXPath, "//section[#id='examples']//input[#name='uploadedfile']", #ScriptDir & "\Screen1.png")
; select two files at once
_WD_SelectFiles($sSession, $_WD_LOCATOR_ByXPath, "//p[contains(text(),'Upload files:')]//input[#name='uploadedfiles[]']", #ScriptDir & "\Screen1.png" & #LF & #ScriptDir & "\Screen2.png")
; accept/start uploading
Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//p[contains(text(),'Upload files:')]//input[2]")
_WD_ElementAction($sSession, $sElement, 'click')
EndFunc ;==>DemoUpload
I am having trouble launching VLC with arguments from python script. I am using python 3.9.6 on Win10 21H1 build 1081.
Running this command works from cmd.exe which I have translated in the python code.
"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe" -I dummy 1.m4a --sout="#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=8000,scodec=none}:std{access=file{no-overwrite},mux=mp3,dst=1.mp3}" vlc://quit
I tried two methods. In method 1 I send arguments separately as below.
import subprocess as objSubProcess
strFileName = "1.m4a"
strNewFileName = "1.mp3"
g_strVLCPath = "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"
strCmd = []
strCmd.append(g_strVLCPath)
strLine = "-I dummy " + strFileName
strCmd.append(strLine)
strLine = "--sout=\"#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=8000,scodec=none}:std{access=file{no-overwrite},mux=mp3,dst="
strLine = strLine + strNewFileName + "}\""
strCmd.append(strLine)
strCmd.append("vlc://quit")
# Run VLC
objSubProcess.run(strCmd)
This code just returns immediately. My guess is VLC launches and exits immediately.
In method 2 I combined all arguments into one as below.
import subprocess as objSubProcess
strFileName = "1.m4a"
strNewFileName = "1.mp3"
g_strVLCPath = "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"
strCmd = []
strCmd.append(g_strVLCPath)
strLine = "-I dummy " + "\"" + strFileName + "\" "
strLine = strLine + "--sout=\"#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=8000,scodec=none}:std{access=file{no-overwrite},mux=mp3,dst="
strLine = strLine + strNewFileName + "}\"" + " vlc://quit"
strCmd.append(strLine)
# Run VLC
objSubProcess.run(strCmd)
Here VLC launches (as I can see in the task manager) but my code hangs and does not return even after a long time.
In both the cases I don't get the .mp3 that I desire.
What am I doing wrong?
If you're going to pass multiple arguments in a list, you have to separate all of them:
strFileName = "1.m4a"
strNewFileName = "1.mp3"
g_strVLCPath = "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"
strCmd = [
g_strVLCPath,
"-I",
"dummy",
strFileName,
'--sout="#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=8000,scodec=none}:std{access=file{no-overwrite},mux=mp3,dst=' + strNewFileName + '}"',
"vlc://quit"
]
# Run VLC
objSubProcess.run(strCmd)
On Windows, shell=True is always implied because of how cmd.exe works. That means that python will assemble your arguments into a single command line and escape or quote things like spaces. This is critical towards understanding why both of your approaches did not work. If you want to pass in a single string you can do that on Windows directly, though I'd still recommend adding shell=True to make your intention clear:
strFileName = "1.m4a"
strNewFileName = "1.mp3"
g_strVLCPath = "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"
strCmd = f'{g_strVLCPath} -I dummy {strFileName} --sout="#transcode{{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=8000,scodec=none}}:std{{access=file{{no-overwrite}},mux=mp3,dst={strNewFileName}}} vlc://quit'
# Run VLC
objSubProcess.run(strCmd, shell=True)
In your first attempt, you have a single list element containing "-I dummy 1.m4a". When you pass that to the shell, it's going to get turned into that string including the quotes, because you specified it as a single argument containing spaces, instead of three separate arguments.
In your second attempt, you concatenated the arguments more-or-less correctly, but didn't add the program name to the string. Since you're passing in a list, python will surround everything with double quotes and escape all the quotes inside.
In first use second argument of subprocess.run() method for passing arguments for vlc Subprocess management.
Two arguments of subprocess.run() method is usefull:
If capture_output is true, stdout and stderr will be captured.
Usefull for troubleshooting.
The timeout argument. If the timeout
expires, the child process will be killed and waited for.
Found the solution. I passed a single string with all arguments as a simple string instead of an array. Here is the code that worked for me.
import subprocess as objSubProcess
strFileName = "1.m4a"
strNewFileName = "1.mp3"
g_strVLCPath = "C:\\Program Files\\VideoLAN\\VLC\\vlc.exe"
strLine = "\"" + g_strVLCPath + "\" -I dummy " + strFileName
strLine = strLine + " --sout=\"#transcode{vcodec=none,acodec=mp3,ab=128,channels=2,samplerate=8000,scodec=none}:std{access=file{no-overwrite},mux=mp3,dst="
strLine = strLine + strNewFileName + "}\""
strLine = strLine + " vlc://quit"
# Run VLC
objSubProcess.run(strLine)
I need to run Libreoffice --covert-to to convert an excel file to html page.
The current code works well within the windows machine. But in AWS, CentOS6, it's producing an error as "Failed to open display".
Here is my code
import subprocess
cwdir = '/opt/libreoffice6.2/program'
excel_path = '/home/ec2-user/PythonCode/testing/Book1.xlsx'
dest_path = '/home/ec2-user/PythonCode/testing'
html_command = ["soffice", "--headless", "--convert-to", "html", "--outdir",
dest_path, excel_path]
subprocess.run(html_command, shell=True, cwd=cwdir)`
I was able to convert excel file to html file with some minor changes. The values inside list is not working so I have to provide the soffice convert-to query as a string value and the folder contains the input excel file and destination folder , where the html file to be stored,must be different.
import subprocess
cwdir = '/opt/libreoffice6.2/program'
excel_path = '/home/ec2-user/PythonCode/testing/Book1.xlsx'
dest_path = '/home/ec2-user/PythonCode/testing/output'
html_command = r"soffice --headless --convert-to html --outdir " + " " + dest_path + " " + excel_path
subprocess.run(html_command, shell=True, cwd=cwdir)
I am trying to split a path into parent and the name.
When trying
String path = "/root/file"
File file = new File(path)
println("Name: " + file.name)
println("Parent: " + file.parent)
We get
Name: file
Parent: /root
With the Windows path C:\\root\\file.exe we get
Name: C:\root\file.exe
Parent: null
Is this the intended behaviour? And if it is how do I get the same result for a Windows path? (If possible please without using regular expressions)
use .replace to change the "\" to "/
String path = "C:\\root\\file.exe"
path = path.replace("\\","/")
File file = new File(path)
println("Name: " + file.name)
println("Parent: " + file.parent)
ok so I have some code in a vbs file, where basically I want to open a CSV file. Perform some changes (I can work that out later) and then save it as an xls. The code works flawlessly when run with a fully qualified file path. However I need the file path to be relative. The files will always be opened and saved to the same path the script is run from. Ive looked at GetParentFolderName and GetAbsolutePathName. However I cant figure how to call the fully qualified path in the text. I've tried just putting the variable where the file name is with and without quotes, appended it with a period.
Any example on building the function or whatever, and then calling it in the code below would be a huge help.
Dim myXL
Const xlDelimited = 1
Const xlWorkbookNormal = -4143
Set myXL=CreateObject("Excel.Application")
myXL.Visible=False
myXL.WorkBooks.OpenText "file.csv", , , xlDelimited, , , , , True
myXL.DisplayAlerts=False
MORE CODE WILL GO HERE
myXL.ActiveWorkbook.SaveAs "new_file.xls", xlWorkbookNormal
myXL.DisplayAlerts=True
myXL.ActiveWorkbook.Close False
myXL.Quit
Set myXL = Nothing
You can get the path of your script by using this code that i Found at an answer about Relative Path
p = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
p should be the path to your script you can then edit "file.csv" to p & "\file.csv" and so.
To point out/emphasize that
you should never use string concatenation to build pathes; .BuildPath() is the way to go
"relative path" needs a clear "relative to what" specification
VBScript's concatenation operator is & not . (dot/period)
:
>> f = WScript.ScriptFullName
>> n = WScript.ScriptName
>> p = goFS.GetParentFolderName(f)
>> a = goFS.GetAbsolutePathName(n)
>> c = goWS.CurrentDirectory
>> WScript.Echo "c", c
>> WScript.Echo "p", p
>> WScript.Echo "?", p & n
>> Wscript.Echo "a", a
>> WScript.Echo "!", goFS.BuildPath(p, n)
>>
c C:\Documents and Settings\eh
p M:\bin
? M:\binivbs.wsf
a C:\Documents and Settings\eh\ivbs.wsf
! M:\bin\ivbs.wsf