I'm using SSIS in conjunction with WinSCP to push a file. Everything seemed to be going OK, but I'm getting an error. It looks like SSIS is, at some point, putting a "phantom space" into my variable for some reason.
The variable is set up like this:
"/command \"open sftp://" + #[User::SFTP_User]+":"+ #[User::SFTP_Pass] + "#" + #[User::SFTP_Site] + " -hostkey=\"\"ssh-rsa 2048 "+ #[User::SFTP_Hostkey] +"\"\"\" \"put -nopreservetime "+ #[User::InventoryFile] + " " + #[User::PurchaseFile] + " " + #[User::SFTP_Location] + "\" \"exit\""
and is used as the script string for WinSCP.com.
When I take the computed value and copy it into Notepad++, I get something like
/command "open sftp://USER:Pas$word#ftp.site.com -hostkey=""ssh-rsa 2048 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00""" "put -nopreservetime \\my\path\file.csv \\my\path\file2.csv /remote/path/" "exit"
HOWEVER!!! Copying/pasting this to the command line, rather than notepad++, however, yields
/command "open sftp://USER: Pas$word#ftp.site.com -hostkey=""ssh-rsa 2048 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00""" "put -nopreservetime \\my\path\file.csv \\my\path\file2.csv /remote/path/" "exit"
ALSO!!! when I run the package, I get an error message:
Error: 0xC0029151 at WinSCP Files to MSA, Execute Process Task: In Executing "C:\Program Files (x86)\WinSCP\WinSCP.com" "/command "open sftp://USER: Pas$word#ftp.site.com -hostkey=""ssh-rsa 2048 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00""" "put -nopreservetime \\my\path\file.csv \\my\path\file2.csv /remote/path/" "exit"" at "\\my\working\path\", The process exit code was "1" while the expected was "0".
Please notice that there is an extra " " (space) in between the "USER:" and the password. This is breaking the command. Also notice that there is an extra space in between the upload files and the upload location (however, this does not seem to have any ill effect). If I copy that whole thing to a command prompt and just remove that space after the colon, it works...
Where are these phantom spaces coming from and/or how do I get rid of them?
I was able to solve this by going into Notepad++ and using the "HEX Editor" plugin to see the hidden characters.
Even "Show all characters" was not showing the hidden characters...
I'm sure that they came from copying from formatted text into the variable. It was really strange that in some instances you could copy/paste them without the formatting and in other circumstances the hidden characters would be there. I usually use notepad++ as a tool (intermediate copy/paste) for removing formatting, but it was not removing these devils.
Anyway, once I found the hidden characters in the HEX editor, I was able to simply remove them from there, switch back to ASCII mode, copy the string and paste it back into the SSIS program and go from there. Problem solved!
Thanks all - your ideas helped get me to the solution.
Related
In this code
I'd like to delete the line 2207 and 2208.
I tried several replace actions in the "Search & Replace" tools but none works
\r\n WriteDumbowLog("MethodName:" & methodName)"
"\n\r WriteDumbowLog("MethodName:" & methodName)"
".$ WriteDumbowLog("MethodName:" & methodName)"
"\n WriteDumbowLog("MethodName:" & methodName)"
The correct regular expression is:
((\r\n)|\n|\r) WriteDumbowLog\("MethodName\:" & methodName\)
I used this extension https://marketplace.visualstudio.com/items?itemName=PeterMacej.MultilineSearchandReplace which doesn't work (oddly) but provide you the correct regex to replace.
I have been trying to get a VBS script to work for a while now with msgbox. When I use a single msgbox statement, it works. As soon as I start adding conditional input options, then it doesn't work.
I posted this question on Super User and I was told to use the "dim" statement, and to post on this website, and I have done both now. Here is some of the code I am trying that works. (Please ignore my example.)
Option Explicit
Dim vbsmsg, vbsyes, vbsno
vbsmsg=MsgBox("Proceeding will wipe the contents of your C: Drive. Proceed?", 1+48, "Format Drive C:")
When I run the above code via a shortcut I get a dialog like this:
But if I add the following, I get a run-time error when clicking "OK" or "Cancel"
If vbsmsg=1 Then
vbsyes=MsgBox("The contents of your C: Drive could not be successfully deleted.", 0+64, "Error Formatting Drive C: - System Error 5")
If vbsmsg=2 Then
vbsno=MsgBox("Not all of the contents of your C: Drive were successfully deleted. Please try again.", 0+64, "Error Formatting Drive C: - System Error 303")
The line/character in the error is between the "0" and "3" in "System Error 303"
I have tried a great deal of troubleshooting already. I have tried altering the dim statement, adding option explicit, using 1 and 2 instead of 6 and 8, etc... nothing seems to work. When I commented out the 2nd part, instead of getting an error after executing the file, it just closed on me. I am positive all of my syntax is correct and in the right format. I changed 1 and 2 to vbOK and vbCancel and when I changed it back it wouldn't work at all and gave me the error pictured on this page right away.
If anyone knows what is wrong with my examples, I would greatly appreciate it. I am fairly new to working with VBS files, but I have been working with .bat files for a long time and none of those principles seem to be working here,
I would appreciate any assistance, even if it is small,
Give this example a try:
Option Explicit
Dim Title,Question
Title = "user input in VBS with MsgBox"
Question = MsgBox("Proceeding will wipe the contents of your C: Drive. Proceed ?",vbYesNo+vbQuestion, Title)
If Question = vbYes Then
MsgBox "We proceed wipping your C:\ drive",vbExclamation,Title
'Call your sub here to continue proceeding your script
Else
MsgBox "Canceling the operation !",vbCritical,Title
Wscript.Quit()
End If
For more information about MsgBox Constants
While #Hackoo's answer is technically correct it doesn't answer the initial question, so I'll attempt to here.
The reason for the error
Microsoft VBScript compilation error: Expected 'End'
is due to the If statement spanning more then one line without an End If to finish the statement block, as in #Hackoo's example adding End If will correct this error.
If for whatever reason you wanted to keep the syntax condensed you weren't far away you had two options;
Put the If statements all on one line
Option Explicit
Dim vbsmsg
vbsmsg = MsgBox("Proceeding will wipe the contents of your C: Drive. Proceed?", vbYesNo + vbQuestion, "Format Drive C:")
If vbsmsg = vbYes Then Call MsgBox("The contents of your C: Drive could not be successfully deleted.", vbExclamation, "Error Formatting Drive C: - System Error 5")
If vbsmsg = vbNo Then Call MsgBox("Not all of the contents of your C: Drive were successfully deleted. Please try again.", vbCritical, "Error Formatting Drive C: - System Error 303")
which can be a little ugly looking at sometimes hard to follow (but that's just my opinion).
Use the Line Continuation Character (_) to allow a single statement to span multiple lines, in VBScript this is also known as a Statement Break.
Option Explicit
Dim vbsmsg
vbsmsg = MsgBox("Proceeding will wipe the contents of your C: Drive. Proceed?", vbYesNo + vbQuestion, "Format Drive C:")
If vbsmsg = vbYes Then _
Call MsgBox("The contents of your C: Drive could not be successfully deleted.", vbExclamation, "Error Formatting Drive C: - System Error 5")
If vbsmsg = vbNo Then _
Call MsgBox("Not all of the contents of your C: Drive were successfully deleted. Please try again.", vbCritical, "Error Formatting Drive C: - System Error 303")
As already mentioned it goes without saying that you should endeavour to use the VBScript Named Constants in code wherever possible instead of hard coded numeric values.
Once upon a time, it was possible to put file:// urls into webpages, and if that URL matched a file on your desktop, why, the file would open on your computer when you clicked on the link.
This functionality has been disabled for security reasons, but I'm trying to recreate it for my own personal use. I'm trying to use a custom URL protocol and an Applescript application as described at http://www.macosxautomation.com/applescript/linktrigger/. I've almost got it working, with one difficulty: A URL can't have spaces in it, so they get escaped, as do other special characters like "&". How can I convince Applescript to open a file with a path with escaped characters in it, such as "/Users/jim/Dropbox/Getting%20Started.pdf"?
tell application "Finder"
open "/Users/jim/Dropbox/Getting Started.pdf" as POSIX file
works fine, whereas
tell application "Finder"
open "/Users/jim/Dropbox/Getting%20Started.pdf" as POSIX file
fails.
Is there an easy (i.e. non-regex) way to make this work?
You can use the open command in do shell script.
Like this:
set tUrl to "/Users/jim/Dropbox/Getting%20Started.pdf"
do shell script "open 'file://" & tUrl & "'"
Try the following:
tell application "Finder"
open my decodeFromUri("/Users/jim/Dropbox/Getting%20Started.pdf") as POSIX file
end tell
after declaring the following handler:
(*
Decodes a string previously encoded for inclusion in a URI (URL).
Note: Uses Perl and its URI::Escape module (preinstalled as of at least OSX 10.8).
Adapted, with gratitude, from http://applescript.bratis-lover.net/library/url/
Example:
my decodeFromUri("me%2Fyou%20%26%20Mot%C3%B6rhead") # -> "me/you & Motörhead"
*)
on decodeFromUri(str)
if str is missing value or str = "" then return str
try
# !! We MUST use `-ne` with `print` rather than just `-pe`; the latter returns the input unmodified.
return do shell script "printf '%s' " & quoted form of str & " | perl -MURI::Escape -ne 'print uri_unescape($_)'"
on error eMsg number eNum
error "Decoding from URI failed: " & eMsg number eNum
end try
end decodeFromUri
I'm trying to read Windows CMD's stdout with AutoHotkey. For example, I'd like to have the output of the setconsole command inside AHK stored in a variable. I already achieved it a while ago, which makes me all the more perplex why it's not working now.
In the AHK forums, there's a rather old thread about CMDret, a DLL based functionality to do exactly what I want. The first problem was to find a working download for it, since all the links in the post were dead. Google gave me another site, hosting v3.1.2. Altough there seems to be a newer one (v3.2.1 respectively 4d Beta), I checked it out and tested a simple example:
msgbox % CMDret(COMSPEC " /C set")
CMDret(CMD)
{
VarSetCapacity(StrOut, 10000)
RetVal := DllCall("cmdret.dll\RunReturn", "str", CMD, "str", StrOut)
Return, %StrOut%
}
Unfortunately, the MsgBox contained nothing. I then checked out RetVal which had a value of 0; and the attached readme says:
If the function fails, the return value is zero.
Further down, it says:
Note: only 32 bit console applications will currently work with the
this dll version of CMDret (v3.1.2 or lower). Calls that require
command.com will likely not produce any output and may crash. To avoid
this I have included a file named "cmdstub.exe" with the download (in
the Win9x folder). This file should be used when calling 16 bit
console applications to enable returning output.
In conclusion, I am not sure what the problem is. My machine is running on 64 bit. But is the corresponding clause in the readme supposed to solely exclude 16 bit systems or does it rather only include 32 bit?
If the computing architecture is probably not the problem, then what could be?
What I am looking for is either one of the following:
Can I fix the problem and keep using v3.1.2?
Has anyone a working source (or even a local copy) of a newer version I could check out?
Is there another approach [library, .ahk code, etc.] I could use for my purpose? (preferably similar, because CMDret seems very straightforward)
If you don't need a live output, you could use the cmd box itself to save a text file of itself and then you could have autohotkey detect when the console's PID finished (using the returned result of runwait and read the outputted file into memory.
So you could do this in your run command (just a regular cmd parameter):
ipconfig > myoutput.txt
exit
Now you have a text file with the ipconfig output in it.
OR
you could do the same thing, but instead of outputting to a text file, you could output to the clipboard, like this:
ipconfig | clip
Then, since the output is on the clipboard, you can easily grab it into autohotkey.
New recommended 2 ways of doing as of Nov 2019 - https://www.autohotkey.com/docs/FAQ.htm#output:
How can the output of a command line operation be retrieved?
Testing shows that due to file caching, a temporary file can be very fast for relatively small outputs. In fact, if the file is deleted immediately after use, it often does not actually get written to disk. For example:
RunWait %ComSpec% /c dir > C:\My Temp File.txt
FileRead, VarToContainContents, C:\My Temp File.txt
FileDelete, C:\My Temp File.txt
To avoid using a temporary file (especially if the output is large), consider using the
Shell.Exec() method as shown in the examples for the Run command.
Example for the Run command - https://www.autohotkey.com/docs/commands/Run.htm#StdOut:
MsgBox % RunWaitOne("dir " A_ScriptDir)
RunWaitOne(command) {
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec(ComSpec " /C " command)
return exec.StdOut.ReadAll()
}
Note: the latter method (shell.Exec) will cause quick display of a cmd window.
You can reduce the duration of its appearance by putting these lines at the top of your script, which will also cause the flickering to happen only once the first time you call the cmd command. From https://autohotkey.com/board/topic/92032-how-to-hide-a-wscript-comspec-window/:
;Following 2 lines : the cmd window will flash only once and quickly
DllCall("AllocConsole")
WinHide % "ahk_id " DllCall("GetConsoleWindow", "ptr")
How about this script, StdoutToVar ?
It has support for 64bit consoles.
http://www.autohotkey.com/board/topic/15455-stdouttovar/page-7
This has been bugging me for some time now - and finally this works !
The only prerequisite for this is MS sqlcmd.exe, a database called AHK_Dev
and of course AHK_DBA to read the value when you wish to make use of it.
PS. make sure you replace {yourDir} and {yourServer} with you own values!
USE AHK_DEV
CREATE TABLE [dbo].[AHK_DOS]([dos_out] [varchar](max) NULL) ON [PRIMARY];
insert into ahk_dos select 'empty'
Create the follow script ... call it dos_out.bat
#echo off
if "%1" == "" (
set v_cmd=""
) else (
set v_cmd=%1
)
set v_cmd=%v_cmd:~1,-1%
SETLOCAL ENABLEDELAYEDEXPANSION
if "!v_cmd!" == "" (
set v_cmd="echo ... %COMPUTERNAME% %USERNAME% %DATE% %TIME%"
set v_cmd=!v_cmd:~1,-1!
)
set v_data=""
FOR /F "usebackq delims=¬" %%i in (`!v_cmd!`) do (
set v_data="!v_data:~1,-1!%%i~"
)
set q_cmd="set nocount on;update ahk_dos set dos_out=N'!v_data:~1,-1!'"
"{yourDir}\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" -S {yourServer} -E -d ahk_dev -Q !q_cmd! -W
set q_cmd="set nocount on;select len(dos_out) as out_len, dos_out from ahk_dos"
"{yourDir}\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" -S {yourServer} -E -d ahk_dev -Q !q_cmd! -W -w 8000
pause
you can run it from AHK using...
dosCmd2db(c) {
runwait, {yourDir\}dos_out.bat "%c%", , , dospid
msgbox %dospid% closed
}
dosCmd2db("")
dosCmd2db("echo This is a test")
dosCmd2db("dir")
As the same field is being updated each time, you would clearly need to do something between each one to make this example useful!
Try it, and let me know how you get on
Regards, Geoff
Just an update to #amynbe answer.
MsgBox % RunWaitOne("dir " A_ScriptDir)
RunWaitOne(command) {
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec(ComSpec " /C " command)
return exec.StdOut.ReadAll() }
Note: the latter method (shell.Exec)
will cause quick display of a cmd window. You can reduce
> the duration of its appearance by putting these lines at the top of
> your script, which will also cause the flickering to happen only once
> the first time you call the cmd command.
You can just do this below to hide cmd and avoid flashing.
MsgBox % RunWaitOne("dir " A_ScriptDir)
RunWaitOne(command) {
DetectHiddenWindows On
Run %ComSpec%,, Hide, pid
WinWait ahk_pid %pid%
DllCall("AttachConsole", "UInt", pid)
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec(ComSpec " /C " command)
DllCall( "FreeConsole" )
return exec.StdOut.ReadAll()
}
I found a script only solution that works for AutoHotKey L 64bit at:
http://www.autohotkey.com/board/topic/67687-ahkahk-lusing-wsh-to-interact-with-command-line-progs/
After playing with it a bit I was able to capthre the entire output of a 40k text file that I listed using the DOS Type command. There is a demo that shows how you can interact with time command, which is nice if you need limited two way interaction with a dos command or batch script.
with the most kind help of an expert, I was able to achieve my target of
1) automatically creating a folder structure based on entry in Column 3; and
2) automatically creating a hyperlink in the appropriate column
The code can be found below
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Columns(3)) Is Nothing Then
Dim tr As String
With Target
tr = ThisWorkbook.Path & "\" & .Offset(, -2).Value
If Len(Dir(tr)) = 0 Then
MkDir tr
MkDir tr & "\Subfolder 1"
MkDir tr & "\Subfolder 2"
MkDir tr & "\Subfolder 3" & "\Sub-subfolder 1"
.Hyperlinks.Add .Offset(, 4), tr, TextToDisplay:="Name"
End If
End With
End If
End Sub
I have been trying to get this to work on Mac but I always get and error 68 and then debugger opens on line
If Len(Dir(tr)) = 0 Then
I have tried changing the \ within inverted commas in the line below
tr = ThisWorkbook.Path & "\" & .Offset(, -2).Value
to
using :
using \
using " " (basically empty space)
I tried changing "(denominator)" to application.pathseparator - still nothing.
Absolutely nothing.
The user has kindly suggested this webpage http://www.rondebruin.nl/mac.htm#Directory
(see section Make a director when it does not exist) which might indeed work - the problem I see with that is that it does not seem to check if a folder already exists and also I am not quite clear on how I would create the sub-folders.
But for some (stubborn/silly?) reason, I am convinced that this must work somehow and I am over-complicating life.
Any thoughts?
Luke
On Mac, you should use forward slash, /.
Since you do not really know whether you're on a PC or a Mac, I suggest to use the filesystem object instead of shell calls you referred to because doing that you would also need to know whether you're calling a windows command line or mac bash script. They're not the same. : )
Here it is described: http://www.tek-tips.com/faqs.cfm?fid=4116