A batch that can write into a .exe cmd prompt? - sql

I would like to make a batch file that can write sql request into an .exe that is running as a cmd prompt window.
My idea was to put my sql script into an .txt file that the batch request and insert into my second prompt window.
I've found something about:
Type 'mytext.txt' | myexe.exe
But its not working.
What I want to do is a Batch that send my sql request into that .exe run as a cmd prompt, so I can automate that process.
Any idea?
Thanks

Depends heavily on the capabilities of that exe-file.
What does it poll for ? Is it written to handle pipes ?
https://technet.microsoft.com/en-us/library/bb490982.aspx gives you an overview of the command redirection operators.
Not knowing what the exe is capable of makes this question really hard to answer.

Related

Send PDF to printer for printing using SSIS

I am trying to accomplish the task: printing PDF files at printer via SSIS silently.
I have tried different ways,
Execute Process Task + PDFtoPrinter: It works on my local machine, printouts available. On server, the job runs successfully, but no printout.
Execute Process Task + Adobe reader: It works on my local machine, but it opens GUI
Script Task + PDFtoPrinter: It works on my local machine, printouts available. On server, similar to solution 1, the job runs successfully, but no printout.
In general, I prefer using PDFtoPrinter.exe, but there is very limited log. I suspected, could it be it needs some wait time, so I put in some waits(30000), still did not solve the problem. Could it be possibly permission related? Having said that I am sure the exe and file folder are reachable.
I also tried to turn on SSIS log and it did not return any valuable insights. Any help is appreciated.
#Fields: event,computer,operator,source,sourceid,executionid,starttime,endtime,datacode,databytes,message
User:ExecuteProcessVariableRouting,xxx,xxx,Print pdf,{xxx},{xxx},06.12.2021 14:06:18,06.12.2021 14:06:18,0,,Routing stdout from variable "User::OutputFromPrinting"
User:ExecuteProcessVariableRouting,xxx,xxx,Print pdf,{xxx},{xxx},06.12.2021 14:06:18,06.12.2021 14:06:18,0,,Routing stderr from variable "User::ErrorFromPrinting"
User:ExecuteProcessExecutingProcess,xxx,xxx,Print pdf,{xxx},{xxx},06.12.2021 14:06:18,06.12.2021 14:06:18,0,,Executing the process "\xxx\PDFtoPrinter.exe" with the arguments ""\xxx\sample.pdf" "Printer1" /s ".
User:ExecuteProcessExecutingProcess,xxx,xxx,Print pdf,{xxx},{xxx},06.12.2021 14:06:34,06.12.2021 14:06:34,0,,Process has exited

Upload file through vba and WinSCP.com

I don't know what is happeining since it's just flashing by the screen. But I have this code in vba.
Shell "H:\Dokument\Avvikelser\WinSCP.com /script=H:\Dokument\Avvikelser\script.txt"
In script.txt i have:
open ftpes://USERNAME:PASSWORD#ftp.SERVER.nu
put H:\Dokument\Avvikelser\lista.txt /Avvikelser/lista.txt
close
As I have understood it I need ftpes to make it passive?
I can't even start WinSCP from cmd prompt
I need to use a cmd style solution as I can't install software on the computer.
The file is not uploaded when the script ends.
WinSCP.COM is only an console interface program for WinSCP.EXE, you need to have both in the same directory.
See https://winscp.net/eng/docs/executables

Alternatives to sqlcmd/best practice

I have created a sql query that updates certain tables taking a CSV file as the input.
I want my co-workers to be able to execute this query as easily as possible. At first, I thought a batch file using sqlcmd was the best solution.
The end product works on my computer, because I have SSMS installed, but no other computer is able to properly launch the batch file.
What is the best way for my end-users to run an sql query? I have thought/researched these solutions:
-Install SSMS or the required tools(don't want each user to have to do this.)
-Install Psexec tools to allow for remote batch launching (also don't like this.)
Is there a better way?
Check SQLS*Plus from www.memfix.com - works the best.
Why don't you create a C-Sharp or VB.Net program that executes the proc and distribute the program to your users?
You don't have to install all of SMS. You can just install SQLServer2008CmdLnUtilsx86.msi for SQL 2008 or go here to get SQLCMD for SQL 2012. http://www.microsoft.com/en-us/download/details.aspx?id=36433. Just be aware that if you install SQLCMD in a bat file and then attempt to use SQLCMD after installing it in that same bat file you have to specify full path to SQLCMD because PATH value is loaded at time bat was started and SQLCMD was not yet available at that time.

Using WinSCP script for SFTP access from SSIS

I am new to WinSCP and am attempting to create a script file that will eventually be used with SSIS to download files from an SFTP site. A lot of the literature WinSCP includes explains the file downloading or uploading portions. For the time being, I just want to create a script to test the connection first and will build from there.
So far I saved the connection in WinSCP and have the following. The below code does not seem to function at all and I am not sure where else to go as I am still reading about the scripting for WinSCP. Is there a way or can someone point me in a direction to see if I am in fact connecting via through the script?
option batch on
option confirm off
open username#address
exit
Not sure what SSIS is (sorry) but I can tell you how I'd set it up from a windows batch file if that helps:
If you are open to using a different software, consider using cygwin. It mimics a linux shell so linux users on windows have a lot of linux utilities handy. That being said, there are some commands which can run on windows straight from command prompt (and thus batchable). What you'd need to do:
1) install cygwin
2) Create a "passwordless" login (using ssh-rsa authentication). To do this start your cygwin terminal and use the commands "ssh-keygen" and "ssh-copy-id" (more on that later)
3) Now you can run "sftp" from the DOS command prompt (does not require cygwin terminal) and sftp to your account. No password required because of step 2).
A few follow up info:
What can run from dos command prompt and what must be run from cygwin terminal?
If you go to the "bin" directory of cygwin (for me it's in c:\cygwin\bin) you can see all the cygwin utilities. Anything with "exe" extension can be run from dos command prompt. If no "exe" extension, must start cygwin terminal first
How to set up ssh-rsa authentication?
You can pretty much google "ssh login without password" and pull up a lot of results. This is common for setting up login from one linux system to another. You would be using the same steps using cygwin on windows. My instructions are here:
http://geekswing.com/geek/unix/how-to-ssh-login-without-a-password-using-ssh-keygen-quick-tutorial/
Storing session settings in WinSCP GUI and trying to access them from WinSCP script running in SSIS is generally a bad idea. I believe there's no example or guide on WinSCP site that would suggest doing that.
WinSCP stores its configuration in registry in HKEY_CURRENT_USER hive. The SSIS typically runs under a dedicated system account, that have its own HKEY_CURRENT_USER hive, and won't see the GUI configuration.
For details see WinSCP FAQ about your problem:
https://winscp.net/eng/docs/faq_scheduler
The best you can do is isolate your your script from configuration by using the session URL with the open command, instead of the stored site name.
See also https://winscp.net/eng/docs/scripting#configuration
Your actual problem can be completely different though. But that's hard to guess as you have not shared any details, such as error message, log file, etc.

Call external batch in WinSCP to capture console output

I have a WinSCP code written for some file transfer ... That's working fine.
My requirement is: before I exit from WinSCP console, I want to execute another batch to take a screenshot of that WinSCP console and then I want to say bye to the WinSCP console. But as long as the second operation is not complete, I don't want to exit the WinSCP console.
I tried:
winscp> Call %some_path%\test.bat
but it says some error like:
The call command executes the command on the server.
You cannot execute local commands from WinSCP script.
But you can execute WinSCP from a batch file and take a screenshot from the batch after WinSCP finishes. Make sure that you execute the winscp.com (not the winscp.exe). The winscp.com is a console application. It inherits the console of the parent batch, so you do not loose WinSCP output after it finishes.
winscp.com /script.txt
%some_path%\test.bat
Anyway, I do not really understand the purpose of this. Wouldn't it be better, if you redirect the output of the winscp.com to a log file?
winscp.com /script=script.txt > output.txt
Or maybe even better, use a log file (the /log=<path> command line parameter). The log includes whole output of the WinSCP console, and lot more.