How can I unzip a varbinary(max) value in a stored procedure? I'd like to implement or invoke a gunzip algorithm within TSQL code, preferably without enabling the CLR.
Look into
sp_OACreate
http://msdn.microsoft.com/en-us/library/ms189763.aspx
sp_oamethod
http://msdn.microsoft.com/en-us/library/ms174984.aspx
You can write the value as a file using file system object, then use a command line gunzip program on it and the read the file using FSO back.
Yes this is not practical but I am not the type of guy who thinks in terms of impossible.
Related
Regarding postgresql, I need to write to a file the result of a loop that does a number of selects.
The "copy to" does not seem to allow to append to a file and moreover is coubersome because does not allow to set delimiters as empty strings and I am obliged to set delimeters to space and tab.
Any other idea for writing a text variable of pgsql to a file, or for appending during "copy to" to the file.
Another problem is that the file name cannot be a variable of pgsql, is there a solution to that ?
Postgres provides for file writing (below is an excerpt from my code).
perform pg_catalog.pg_file_unlink(fn); -- I delete the file
perform pg_catalog.pg_file_write(fn,r,false); -- I accumulated the string to write into r.
These functions are available with the adminpack that must be installed as e.g. described in adminpack installation.
The above functions solve both the problem of writing to a file with the name given by an expression and the problem of writing an expression to the file.
In my case giving only a file name the file gets written in: /var/lib/postgresql/9.5/main (I use ubuntu).
I am trying to run tests in UFT by running a .vbs file. I am also passing arguments through command line. .vbs file reads the arguments and sets the environment variable of UFT. Hence, I can read them inside UFT.
qtApp.Test.Environment.Value("First_Argument") = WScript.Arguments.Item(0)
qtApp.Test.Environment.Value("Second_Argument") = WScript.Arguments.Item(1)
After that, I want to get a number as an output from UFT because I will use that output to pass it to the next command in command line.
The Test Parameters Object can be a way , more detailed in the Automation Object Documentation
You will have to define the TestParameters of the TestCase from the UFT IDE(manually) there is no way to define them automatically. If you declare them as in and out type, and change their value as a part of a Test Case, you would be able to read it afterwards from the vbs (Do not open a new Test Case until you did not read out the preferred values)
Although this is a working (and standard) way for exchanging parameters between the driver script and the TA Robot(UFT) I would advise you to use a simple file based way of doing this - managing test parameters can be very time consuming.
Tell the script via an Environment variable the path of the xml / json or simple text file where you expect the results to be written and when the test is done, read the content of the file (assuming the test will write into that file)
The plain old file way should not be underestimated especially in such circumstances.
I have an unusual requirement. I have a big config /perl file in which I would like to change the value of one variable before my run. To avoid manually finding the variable and changing it's value, I would like to write a perl script to change the name of the variable. Is that possible to do this without parsing every single line of big perl file, creating a temporary copy and overwriting old file.
Something is parsing this file at some point, right? Give it a list of things to substitute and you can have it only do the substitutions when it needs it. This avoids a big pre-startup overhead and if the config file is sparsely used, will result in a faster overall run.
So just make the thing reading it look for certain patterns to substitute in and a file (or passed in on the command line or environment variables, or...) for the values it should use and go from there.
If you don't have control over the parser, then there's not much to do. You could one-time pre-process the config file to determine EXACTLY where the substitutions need to be and write a faster processor, since it won't have to do any string parsing for regular expressions, just moving a bunch of bytes as fast as your computer can move them to the new file with the substitutions in place.
I'm trying to write a script that will grab logs across a network and parse them for relevant information and perform some action (email if there's a critical issue, simply write to a log file if its a warning). I am using an AIX machine with syslogd to process the logs. Right now it is performing like usual, writing all logs to files ... a lot of files.
I was advised to use Perl and Named Pipes to implement the script. I've just spent some time reading up on named pipes and I find them quite fascinating. However, I'm stumped as to how the "flow" of information should work in this situation and how to make perl handle it.
For example, should I create a fifo outside of the script and tell syslogd to write to it by default and have my script on the other end parsing it? Can Perl do that and (for you sysadmins) is this a smart/possible option?
This is my first encounter with Perl and with named pipes.
You can surely create a named pipe in Perl, although it seems to me that for what you are trying to do, it is better to create the named pipe outside of perl, as you are suggesting, and then have syslogd write to it, and read the pipe from perl.
I don't know very well AIX, but this could do for creating a pipe (source):
mkfifo -p /var/adm/syslog.pipe
To have syslogd write to it, define this in /var/adm/syslog.pipe:
*.info |/var/adm/syslog.pipe
Then:
kill -HUP `cat /var/run/syslogd.pid`
You could also put all this stuff into your perl script: in case the pipe did not exist or syslogd were not using it, the script would arrange all required things for you.
Possibly you could provide some more details as to what you are trying to do, if you need more help.
I have a quick question about creating files with perl and executing them. I wanted to know if it was possible to generate a file using perl (I actually need a .bat script) and then execute this file internally to the program. I know I can create files, and I have with perl, however, I'm wanting to do this internally to the program. So, what I want it to do is actually create a batch script internally to the program (no file is actually written to the disk, everything remains in memory, or the perl program), and then once it completes the writing of the file, I'd like to be able to actually execute this file, and then discard the file it just wrote. I'm basically trying to have it create a batch script on the fly, so that I can just have output text files from the output of the script, rather than creating the batch script on disk, then executing it, and then deleting the batch file from disk when its done.
Can this be done and how would I go about doing this?
Regards,
Drew
Do you really need a batch script? Perhaps everything you want to do can be done directly from Perl or invoked directly by Perl via its system command.
If a batch script is essential, what's wrong with creating a temporary file for the script and then executing it with system? See File::Temp, which will even delete the temporary file automatically after you are done.
If the virtual-batch-file strategy is unavoidable, you might be able to leverage the /C and maybe /S options of cmd. Something like this:
use strict;
use warnings;
my #batch_commands = (
'dir',
q{echo "Make sure quoting isn't busted"},
'ipconfig',
);
# Use & or &&, depending on your needs. Run `cmd /?` for details.
my $virtual_bat_file = join " &\n", #batch_commands;
system "cmd /C $virtual_bat_file";
But this feels very wrong. There has to be a better way to accomplish whatever the larger goal of your application is. By the way, when you run cmd /? to learn about /C, /S, and & vs. &&, you'll quickly appreciate how terrible it is in the Land of Batch. Stay away if at all possible.
open the file; create the contents; close the file; execute the file (with system(), for example); remove the file.