using output from first line of code for input to 2nd line of code - batch-file

I am getting a "File not found" error with trying to run Outlook in batch. Most likely due to an error in the way I am formatting the code. The script takes the contents of clipboard provided by 'getclip' as %1, zips it to clips.zip, uses && to pass to ipmnote which attaches it to a pre-loaded Outlook email
My original layout (which works) uses more lines of code and includes a mid-step of creating a file to be compressed. In trying to simplify the routine, I am getting errors saying Outlook cannot be found.
Outlook.exe is already in my System Path and I normally call it in using only the exe name. But I get the same "can't be located" error even when adding full path the file as shown here.
getclip>7z.exe a Clips.zip %1 -y && "C:\Program Files (x86)\Microsoft
Office\root\Office16\OUTLOOK.exe" /c ipm.note /m "email&subject=CLips.zip"
/a Clips.zip

Thanks for the quick reply. But the problem was the attachment. The error shown is somewhat open to interpretation since it implies that the issue is that Outlook cannot be found. In fact, what it could not find was the "clips.zip" file needed to attach it. Once i added the path to find the attachment, it works perfectly.
Sometimes, it helps to write in and ask the question. By following testing the sequence for each step of the outlook command, i found the issue was only there when i added the attachment with the /a at the end. By giving the full path to find 'clips.zip', all errors are gone and the email is perfect.
The broken line in the code was created by posting the code using the "Code" button. I added characters as needed to force it to display properly
I am sure there is a better way and I started to mention this but i figured most people would know that the proper path to Outlook especially being in quotes and all would not have a carriage return in the middle"

Related

Batch File Calls VB Script & Passes Filename as String Only

I have a batch file that calls a VB Script file. This VB Script comes from MS Office Suite and is located in the Installed Folder. My file calls the VB Script and pipes it to a file using the > symbol. This works if your redirect is a string. I was wondering how to redirect to a file using a variable.
I'm only including a small fraction of the code showing how I want it to work.
This, as written, works. However I want my batch file to use a variable instead of the text in quotes. In fact, my batch file creates the path depending on where the batch file is located.
::Create file and display on screen
Echo Writing Information to File: "OfficeStatus.txt"
Call cscript ospp.vbs /dstatus > OfficeStatus.txt
Echo.
When written as shown below, it does not work:
::Create file and display on screen
Echo Writing Information to File: "OfficeStatus.txt"
Call cscript ospp.vbs /dstatus > %_sLogFile%
Echo.
I don't know if the issue is because of the redirect not able to handle a variable or not. An example of what might be in the variable:
_sLogFile=E:\UserName\Documents\Status\OfficeStatus.txt.
Any thoughts would be great.
The variable, by the way, correctly contains the path and filename... so that's not the issue.
it does not work means did not do what I expected and unfortunately does not tell us what it did do.
Did it crash the system? Create an error message (If so, what message)? Create an output file in an unexpected place??
Personally, I'd suspect what you have concealed as username. Without knowing precisely what that text is, we start guessing, which isn't a logical approach. It doesn't have to be the real username, substitute Fred Bloggs for the real name to mask it if necessary.
I believe that username may either be %username% to retrieve the name from the system, or a real literal. The problem with this is that such names often contain spaces, you'd need to "Enclose the full filename in quotes".
See - had you told us _sLogFile=E:\Fred Bloggs\Documents\Status\OfficeStatus.txt it would all have been a lot clearer - presuming that my guess as to the cause of the problem is correct.
Perhaps you should look for files named like E:\Fred which is where the expected output may have ended up.

WinSCP "Too many parameters for command 'open'." error

I am trying to connect to an SFTP with the following command to move all .csv files from one location to another and I'm getting the "Too many parameters for command 'open'." error.
option echo off
option batch on
option confirm off
open sftp://XXX#XXX.com/ —hostkey="ssh-rsa 2048 XX:XX:XX:XX:XX:XX:XX" —rawsettings ProxyMethod=3 ProxyHost=proxy.uk.XXX.com
cd /XX/XX/XX/IN/LOAD
lcd \\XX.local\EMEA\XX\XX\Import_Location
put *.csv -nopreservetime=on -nopermissions=on
exit
I added the —hostkey parameter due to the "The server's host key was not found in the cache" error, the batch file was working fine before that, but I want to correct the host key error.
I checked all the dashes, the quotes, the only thing I'm confused about is whether the hostkey parameter is correct. The information online on WinSCP and some forums says you have to use SHA-256 fingerprint of the host key only which is a different format to the MD5 detail XX:XX:XX:XX.... Please can you help which one it is?
—hostkey="ssh-rsa 2048 XX:XX:XX:XX:XX:XX:XX"
OR
—hostkey="ssh-rsa 2056 AbC50IDzyx.....="
This is a similar query to mine, but I cannot see what the difference is so that theirs works and mine doesn't. Thank you.
The symbol you have at the beginning of —hostkey and —rawsettings is not a simple hyphen-minus (-), but em-dash (—).
Please use hyphen-minus (-) – what is the dash that you find on the standard English [and other] keyboards.
Or even easier, have WinSCP GUI generate a script template for you.
So actually you have the very same problem as in WinSCP forum post you referred to.
Other questions with the same error message, but different problem:
WinSCP command line - Too many parameters for command 'open' when using -rawtransfersettings switch
Getting "Too many parameters for command", when calling WinSCP command-line from VBA
FTP "Too many parameters for command 'synchronize'" with WinSCP
Obtaining the correct hostkey fingerprint:
https://winscp.net/eng/docs/faq_hostkey

Compiling LaTeX from notepad++ and opening with sumatra. ForwardSearch doesn't work if file path contains umlauts

I've had this small problem for quite some time now and I haven't been able to find a solution even after excessive googling.
In this guide it is described how LaTeX can be written and compiled using npp++ and nppExec together with SumatraPDF.
Through some clever scripts and the use of DDE commands (through CMCDDE.exe), it is even possible to use sumatra's ForwardSearch to jump back and forth from the .tex to the .pdf. Everything works great, unless the path to the .tex file contains a character that's not in the English alphabet (for example åäö).
The CMCDDE command then fails because the path sent to sumatra's ForwardSearch reads (for example) C:\†„” instead of C:\åäö. This has to be an encoding issue and I haven't been able to find a working solution.
So, if I have this .tex file C:\åäö\MWE.tex with
\documentclass{article}
\begin{document}
Hello World!
\end{document}
it won't open correctly when using the batch script described in the link above. These are the problematic batch file lines:
::Writes the commands that are to be executed using CMCDDE.exe (through cmcdde.tmp)
echo SUMATRA>"%~dp1build\cmcdde.tmp"
::%~dp1build transforms into C:\åäö\build for the MWE
echo control>>"%~dp1build\cmcdde.tmp"
echo [ForwardSearch("%~dp1build\%~n1.pdf", "%~f1", %2, 0, 0, 0)]>>"%~dp1build\cmcdde.tmp"
:: This gives the following line in cmcdde.tmp: [ForwardSearch("P:\Documents\†„”\build\MWE.pdf", "P:\Documents\†„”\MWE.tex", 3, 0, 0, 0)] (in ANSI encoding)
"P:\Documents\localtexmf\cmcdde.exe" #"%~dp1build\cmcdde.txt"
:: This fails because the path P:\Documents\†„”\build doesn't exist (P:\Documents\åäö\build does)
Ideas I've had and tried:
I tried changing the encoding by using chcp 65001 and chcp 865 but
haven't been able to get it to work.
I have also tried using a
search and replace
script to go through the cmcdde.tmp file before executing it but it didn't
succeed (I'm not sure which signs I should search for to exchange for
åäö, †„” or åäö or ├Ñ├ñ├ or other?)
I have also tried putting
cmd /c or cmd /a /c before the echo commands (as sort of described
here)
but it doesn't seem to make a difference.
Please let me know if something which parts of the question that are unclear.
I managed to find a solution. Turns out using the code page 1252 solves the problem.
So putting chcp 1252 at the beginning of the batch file is the solution. However, if you're using other none standard characters than me (other then the ones in the nordic alphabet), I'm guessing you might need another code page.
Experiment and test different ones until you get it working.

My batch script is reporting an error stating "was unexpected at this time"

The Windows batch file I am trying to run contains the following assignment:
set ANT_HOME="C:/Program Files/apache-ant-1.8.4"
The offending line is:
call %ANT_HOME%/bin/ant -f ../config/common.xml start_db
And when I run the script with echo on I get:
call "C:/Program_Files/apache-ant-1.8.4"/bin/ant -f ../config/common.xml start_db
Files/apache-ant-1.8.4""=="" was unexpected at this time.
I've moved the second quote to to the end of the path, after the ant, but I receive the same error message.
If ant were an .exe I would say your code should work. But I suspect that ant is a batch file, and the error is occurring within the ant script.
I base my conclusion on your error message - specifically the following portion of it: ""=="". The error message is a batch parsing error, and I don't see how your code could generate those characters. So I figure ant must be a batch script that is causing the problem.
I suspect ant.bat has #echo off at the top, so you are not seeing the actual line that is failing.
Not having access to the ant.bat script, I couldn't possibly diagnose exactly what is failing, nor can I guess on how to fix it.
Update - exact problem found
I found a copy of ant.bat online.
It has the following line of code within:
if "%ANT_HOME%"=="" set ANT_HOME=%DEFAULT_ANT_HOME%
Your definition of ANT_HOME includes enclosing quotes, so the code is trying to execute
if ""C:/Program Files/apache-ant-1.8.4""=="" set ANT_HOME=%DEFAULT_ANT_HOME%
The space is not quoted, and you have your error.
All you need to do to fix everything is to remove the quotes from the definition of ANT_HOME, and then add quotes to your CALL statement:
set "ANT_HOME=C:/Program Files/apache-ant-1.8.4"
call "%ANT_HOME%/bin/ant" -f ../config/common.xml start_db
Forward-slashes are not always reliable as folder delimiters within Windows. See Why does the cmd.exe shell on Windows fail with paths using a forward-slash ('/'') path separator?.
Better to use back-slashes.
set "ANT_HOME=C:\Program Files\apache-ant-1.8.4"
call "%ANT_HOME%\bin\ant" -f ..\config\common.xml start_db
The quotes have to completely surround a file name. You can't use them for partial names. Try this instead:
set ANT_HOME=C:\Program Files\apache-ant-1.8.4
call "%ANT_HOME%\bin\ant" -f ../config/common.xml start_db
Oh, and I changed some of your slashes to backslashes (DOS doesn't like forward slashes). I assume you are allowed to use / in that parameter you are passing though.

XCOPY exclude list ignored after first exclusion

I have a batch file I've created which uses xcopy to copy a dir, and child dirs, and merge them into one file. (ie. all my modulised development css stylesheets merged into one production stylesheet).
Everything is good, apart from the fact that when I reference the excludelist.txt, it only excludes the first line, and not the subsequent files I want excluded.
Anyone fancy a crack at this? You'd be most helpful.
Here's the code:
XCOPY C:\xampp\htdocs\PROJECT\css\*.* C:\temp /S /I /Y /EXCLUDE:C:\xampp\htdocs\PROJECT\exclude.txt
...and inside my exclude.txt is...
1.css
2.css
3.css
4.css
5.css
///// I know the code works (to an extent) because it is infact excluding file 1.css -- just not the ones below it. Am I right to put each exclusion on a new line?
I use the following,
xcopy "C:\users\dad\*.*" dad /s /d <yesnoyesno /EXCLUDE:excluexclu 1>cop.txt 2>err.txt
as somewhere on the web I saw a note to the effect that the /Y switch could not be used directly with an exclude file.
What I wanted to point out here, was the useful output files 1 & 2, which detail the success & failure issues.
Mine shows only success.
The short answer: Create a new text file, type the entries and save the file.
The longer explanation: I ran into this very issue on a Windows 2008 server today. I tried all kinds of things to get it to work. Forced notepad to save the file as ANSI, Unicode and UTF-8 but all of them had the same problem. Finally I started thinking about the fact that I put the file on the server via FTP and it's quite likely that FTP tweaked the file format. I created a new text file on the server, typed all the same entries in the new file and now it works.
I had a similar problem. I was trying to exclude all files with a certain extension in the root folder and any sub-folders and it didn't work. The reason was I was putting *.pdb instead of just .pdb. The newline/carriage return thing was a total red herring for me.
So my file just looked like:
.pdb
.obj
.vb
.cs
You seem to be using xcopy correctly - each exclusion file (or match depending on wildcards) should be on a new line within the file. So far I've been unable to reproduce the behaviour you're experiencing.
Is the exclude.txt listing you've given above a test file, or are they the actual css names?
What are the names of the other files that your batch file is supposed to copy?
Edit:
That the xcopy is failing to exclude further files after a single match is giving me most pause. I thought it might be to do with the type of carriage-return that was used in the exclude file, but xcopy handles unix-style carriage-returns just fine.
Can you re-verify that the correct exclude file is being used?
Try forcing it to save with ANSI encoding on your text editor.
I was having a similar issue and that did it.

Resources