unzipping a file using 7zip in SSIS - sql-server

I'm currently using a Process Task to try to unzip a file in SSIS with the following settings:
I'm using this statement:
e "Inventory.zip" -o"c:\broinctarget\" -y
I'm actually generating the above statement using:
"e " +"\"" + "Inventory.zip" + "\"" + " -o" + "\"" +#[$Package::targetLocation] +"\""+" -y"
#[$Package::targetLocation]
Am I doing something that is obviously wrong?
How do I unzip a *.zip file using 7zip in SSIS?

I ran into a similar issue on an SSIS package I wrote. I ended up generating a batch file in a c# script, and just calling that batch file in an execute process task.
I also needed the flexibility to add a password option based on some table parameters.
I realize it's an extra step, and if I were unzipping a ton of files it might matter, but for a For-Each container that is going to hit 5-10 files, its not a big deal - and you can easily read the batch file to see what was run too.
string exe7z = Dts.Variables["s7ZIPPath"].Value.ToString();;
string zipFile = Dts.Variables["sZIPFile"].Value.ToString();
string outPath = Dts.Variables["sFileLocation"].Value.ToString();
string password = Dts.Variables["sZIPPassword"].Value.ToString();
if (password.Length > 0)
{
password = "-p\"" + password + "\"";
}
if (!(outPath.EndsWith("\\")))
{
outPath = outPath + "\\";
}
string batchFile = outPath + "unzip.bat";
Dts.Variables["sZipBatchFile"].Value = batchFile;
using (StreamWriter writer = new StreamWriter(batchFile))
{
writer.Write("\"" + exe7z + "\" e \"" + zipFile + "\" -o\"" + outPath + "\" -y " + password);
}

Related

Parse parameterized .exe with variables out of PowerShell in a new cmd window

I wrote a PowerShell GUI for a parameterized .exe file.
The .exe needs to be run with 2 parameters, a slected file and a report format.
I've built my event like that:
$VBVGUIValidateButton.Add_Click({
if ($Global:SelectedFile -eq $Null) {
[System.Windows.Forms.MessageBox]::Show("No File Selected. Please select a file !", "Error", 0, [System.Windows.Forms.MessageBoxIcon]::Exclamation)
} else {
if ($VBVGUIXMLReport.Checked -eq "True") {
Choose-Folder
#$ReportString = "$ReportLocation" + "$ReportName" + ".xml"
$ReportString = "$Global:SelectedFolder" + "\" + "$ReportName" + ".xml"
Set-Location -Path $ValidatorPath
.\TOOL.exe /file:$Global:SelectedFile /report:$ReportString /format:xml
[System.Windows.Forms.MessageBox]::Show("Validation process finished !" , "Information", 0, [System.Windows.Forms.MessageBoxIcon]::Information)
} else {
Choose-Folder
#$ReportString = "$ReportLocation" + "$ReportName" + ".html"
$ReportString = "$Global:SelectedFolder" + "\" + "$ReportName" + ".html"
Set-Location -Path $ValidatorPath
.\TOOL.exe /file:$Global:SelectedFile /report:$ReportString
[System.Windows.Forms.MessageBox]::Show("Validation process finished !" , "Information", 0, [System.Windows.Forms.MessageBoxIcon]::Information)
}
}
})
What I especially want is opening/parsing the .exe file in a new CMD window, so the process of the TOOL.exe can be seen.
This part here:
Choose-Folder
#$ReportString = "$ReportLocation" + "$ReportName" + ".html"
$ReportString = "$Global:SelectedFolder" + "\" + "$ReportName" + ".html"
Set-Location -Path $ValidatorPath
.\TOOL.exe /file:$Global:SelectedFile /report:$ReportString
[System.Windows.Forms.MessageBox]::Show("Validation process finished !" , "Information", 0, [System.Windows.Forms.MessageBoxIcon]::Information)
The TOOL.exe writes information out in the CMD if it's exectued directly. If I execute it via my PowerShell GUI, the GUI "freezes" (obvious as it is working in the background) and I cannot see the progress. How can I achieve this ?

how to extract test log from MTM ?

I'm testing a project and all my test cases are in MTM , I'm looking for a way to extract all the test result we have in the MTM in a separate file , is there any way to do that ? please share if you have any idea
thanks a lot
If you wish to export the results of an automated run, you can download the .trx (test run execution) file from the attachments section and use XSLand XSLT to create an html report from it (you can also use the command-line tool tcm.exe run /export to get a .trx file).
But if you created the test run by manual execution, this won't be possible. The only way to get a "result file" would be to parse the result of the test run using the TFS API (in C# or Powershell via TfsTeamProjectCollection from Microsoft.TeamFoundation.TestManagement.Client and store it in a file.
Or you can use the TFS Rest-API with this PowerShell-Script (save as .ps) which lets you query a JSON and extract the data you want and display it the way you want to:
$RunId = Read-Host -Prompt "TFS Run Id"
$Url = "http://<tfsurl>/tfs/<CollectionName>/<TeamProject>/_apis/test/runs/$RunId/results"
$Client = New-Object System.Net.WebClient
$Client.Credentials = New-Object System.Net.NetworkCredential("<username>", "<password>", "<domain>")
$Json = $Client.DownloadString($Url) | ConvertFrom-Json
$Dict = #{}
ForEach($Test in $Json.value)
{
$Key = "Run " + $Test.testRun.name + " [" + $Test.testRun.id + "]"
$Val = $Test.testCase.name + " [" + $Test.testCase.id + "]" + " = " + $Test.outcome
if (!$Dict.ContainsKey($Key))
{
$List = New-Object System.Collections.ArrayList
$Dict.Add($Key, $List)
}
$IgnoreIndex = $Dict[$Key].Add($Val)
}
ForEach($Key in $Dict.Keys)
{
Write-Host $Key
ForEach($Val in $Dict[$Key])
{
Write-Host $Val
}
}
Exit
(replace values like <xxx> with yours)

batch file for runing a java command

I have to run the following command for hundreds of .docx files in a directory in a windows in order to convert them to .txt.
java -jar tika-app-1.3.jar -t somedocfile.doc > converted.txt
I was wondering if there is any automatic way such as writing a ".bat" file to do this.
Yes you can do it in batch. An example isn't coming to mind in order to help you but since you are running java commands anyway you can do it through java too. Here is an example of how you can be running the commands on CMD from java. Hope this helps.
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
try {
executeCMD("java -jar tika-app-1.3.jar -t " + <YOUR_DOC_FILE> + " > " + <TXT_NAME_OF_FILE> );
}catch(Exception e){
e.printStackTrace();
}
private void executeCMD(String command) throws Exception{
Process process = Runtime.getRuntime().exec(command);
printMsg(command + " stdout:", process.getInputStream());
printMsg(command + " stderr:", process.getErrorStream());
process.waitFor();
if(process.exitValue() != 0)
System.out.println(command + "exited with value " + process.exitValue());
}
private void printMsg(String name, InputStream ins) throws Exception {
String line = null;
BufferedReader in = new BufferedReader(new InputStreamReader(ins));
while((line = in.readLine()) != null){
System.out.println(name + " " + line);
}
}
UPDATE
Okey here is the way simpler batch way which I couldn't think of yesterday :D
for /r %%i in (*.doc) do java -jar tika-app-1.3.jar -t %%~ni > %%~ni.txt
It reads all the *.doc files in the directory it is executed, also the "~n" is in order to list only the filenames ( in your example "somedocfile" ) because otherwise it will do something like "C://...../somedocfile.doc" and changing the extension might be annoying.

How do I run a gawk file with spaces in the path name?

I am trying to run the following line in an awk script and I am getting an error. I think the error is because the filename has spaces in it. How do I call the file without changing the path name (i.e. rename the file/path)? The code is contain within a BEGIN{} block.
INSTALLATION_LOCATION_GAWK = "L:/CPU_Analysis/Sanity/CPUAnalysisApp/cpu_analysis_application/"
DATA_SUMMARY_LOCATION_GAWK = "C:/Program Files/CPU Analysis/data/data_summary.csv"
....
command = ("gawk -v version=" dataArray[1] " -v date=" dataArray[2] " -v platform=" dataArray[3] " -f ") (INSTALLATION_LOCATION_GAWK "generateSanity_Scripts/removeData.awk ") DATA_SUMMARY_LOCATION_GAWK
system(command)
UPDATE: I also ran into the issue that you cannot copy/save/edit files in C:\Program Files due to windows restrictions. I solved this problem by moving my project to C:\My Programs.
I think it will be a case of providing quotes in the command string:
command = "gawk"
command = command " -v version=\"" dataArray[1] "\""
command = command " -v date=\"" dataArray[2] "\""
command = command " -v platform=\"" dataArray[3] "\""
command = command " -f \"" INSTALLATION_LOCATION_GAWK "generateSanity_Scripts/removeData.awk\""
command = command " \"" DATA_SUMMARY_LOCATION_GAWK "\""

Accept parameters from a .Net console app into a Batch file

I am trying to pass parameters from a .Net console app to a batch file. The parameters are not coming into the batch file.
How can I properly set up passing the parameters into the bat file?
Here is the method in the console app that I'm executing.
private static int ProcessBatFile(string ifldr, string ofldr, string iext, string oext, Int16 filewidth, Int16 fileheight, Int16 ctr)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = ConfigurationSettings.AppSettings.Get("BatProcessDir") + "imagemagick.bat";
psi.Arguments = "-ifldr=" + ifldr + " -ofldr=" + ofldr + " -iext=" + iext + " -oext=" + oext + " -iwid=" + filewidth + " -ihgt=" + fileheight;
psi.UseShellExecute = false;
Process process = new Process();
process.StartInfo = psi;
process.Start();
return ctr;
}
Below, is the code in the bat file I'm trying to execute:
#echo on
echo %ofldr%
echo %ifldr%
echo %iwid%
echo %ihgt%
echo %oext%
echo %iext%
If you pass them as paramters, you can do this in the c# code:
psi.Arguments = ifldr + " " + ofldr + " " + iext + " " + oext + " " + filewidth + " " + fileheight;
and do this in the batch file:
#echo on
set ifldr=%1
set ofldr=%2
set iext=%3
set oext=%4
set iwid=%5
set ihgt=%6
echo %ofldr%
echo %ifldr%
echo %iwid%
echo %ihgt%
echo %oext%
echo %iext%
As an alternative solution, you can also directly modify the environment before executing the batch file using System.Environment.SetEnvironmentVariable:
System.Environment.SetEnvironmentVariable ("ifldr", ifldr);
....
This causes less problems if the parameters may contain spaces.

Resources