Execute a bash script in Unity Cloud Build - c#

My requirement is to execute a bash script "PostProcessShellScript.sh" in PostProcessBuild. Unity build runs fine, but build fails in Unity Cloud Build.
Below is my code :
public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) {
.....
string scriptPath = Application.dataPath + "/Plugins/Android/Editor/PostProcessShellScript.sh";
//Runs fine on Local Unity build
//RunInShell("C:\\Program Files\\bash.exe","/" + scriptPath + " " + " " + "/" + apkPath + "/"+ "/" + apkName, false);
RunInShell("open","/" + scriptPath + " " + " " + "/" + apkPath + "/"+ "/" + apkName, false);
}
public static void RunInShell(string file, string args, bool waitForExit = true) {
System.Diagnostics.Process ppScriptProcess = new System.Diagnostics.Process();
ppScriptProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
ppScriptProcess.StartInfo.FileName = file;
ppScriptProcess.StartInfo.Arguments = args;
ppScriptProcess.StartInfo.UseShellExecute = false;
ppScriptProcess.StartInfo.CreateNoWindow = false;
ppScriptProcess.StartInfo.RedirectStandardOutput = true;
ppScriptProcess.StartInfo.RedirectStandardError = true;
ppScriptProcess.Start ()
}
Error details on UCB :
! Unity player export failed!
! build of 'default_-android' failed. compile failed
Publishing build 22 of surbhijain87/roll-a-ball-game for target
'default_-android'...
publishing finished successfully.
done.
Build step 'Execute shell' marked build as failure
postbuildstatus finished successfully. Finished: FAILURE

too implicit.
I am using the shell scripting to resolve the issues.
UCB running on mono and shell scripting looks like the way to go.
Your resolution: convert the code to a shell script and attach on the UCB config from the UI

Related

Run command line with date parameters with C# in SSIS (2015)

I need to run a command line on a Windows server with date parameters using C# in SSIS (2015)
The command line example:
D:\TEST >dotnet TEST.dll --fromDateTime "2018-11-21" --toDateTime "2018-11-22"
Can you assist me in the script?
Thanks
Thank you all for your assistance.
I found the answer to my problem:
Can't use the SSIS Execute Process Task since it is applicable to EXE or BAT
Don't want / Can't change my DotNet DLL to an EXE since it is very limiting and the project includes many other factors that are not under this issue (and the dev is done by other teams)
here is the C# with the answer - it works! :)
public void Main()
{
string FromDate = Dts.Variables["User::FromDate"].Value.ToString();
string ToDate = Dts.Variables["User::ToDate"].Value.ToString();
string TEST_Path = Dts.Variables["$Package::TEST_Path"].Value.ToString();
string TEST_ExePath = Dts.Variables["$Package::TEST_ExePath"].Value.ToString();
var strCmdText = #"c:\program files\dotnet\dotnet.exe";
var parameters = TEST_ExePath.ToString() + " --fromDateTime " + FromDate.ToString() + " --toDateTime " + ToDate.ToString();
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo = new System.Diagnostics.ProcessStartInfo(strCmdText, parameters);
p.StartInfo.WorkingDirectory = TEST_Path;
p.StartInfo.UseShellExecute = false;
bool fireAgain = false;
try
{
p.Start();
}
catch(Exception e)
{
Dts.Events.FireError(0, "Script Task Example", "Exception encountered: " + e.ToString(), String.Empty, 0);
}
p.WaitForExit();
Dts.Events.FireInformation(0, "Script Task Example", "Exit code = " + p.ExitCode.ToString(), String.Empty, 0, ref fireAgain);
Dts.TaskResult = (int)ScriptResults.Success;
}

Execute jar file in c#

I have a problem with executing the jar file in c#.
This jar file is epubcheck.jar
here is my code to run the file
public string IdpfValidateEpub(string epub)
{
try
{
string result = null;
string epubCheckPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "epubcheck.jar");
string arguments = "java -jar" + " \"" + epubCheckPath + "\"" + " \"" + epub + "\"";
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
//strCommand is path and file name of command to run
pProcess.StartInfo.FileName = #"cmd.exe";
//strCommandParameters are parameters to pass to program
pProcess.StartInfo.Arguments = arguments;
Debug.WriteLine("arguments: " + pProcess.StartInfo.Arguments);
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.CreateNoWindow = false;
//Set output of program to be written to process output stream
pProcess.StartInfo.RedirectStandardOutput = true;
//Start the process
pProcess.Start();
//Get program output
result = pProcess.StandardOutput.ReadToEnd();
//Wait for process to finish
pProcess.WaitForExit();
return result;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
Debug.WriteLine(ex.StackTrace);
throw ex;
}
}
But the program is not running at all. I also set the property to show the window. So i can see if its running or not. But it only shows the command prompt like this
I also printed the arguments i passed in the System.Diagnostics.Process in order to check if the arguments are correct.
After the program printed the arguments. i just copied it and paste in the command prompt. And the program works as expected. But why does it doesn't work in my c# code?
Thank you so much.
Java is a program in its own right, so you don't actually need cmd.exe to run it.
Change your arguments to the following so that you're passing the arguments for java:
string arguments = "-jar" + " \"" + epubCheckPath + "\"" + " \"" + epub + "\"";
And then simply start java instead of cmd:
pProcess.StartInfo.FileName = #"java";

Value assigned more than once in single assignment

I made script task that's downloading and saving on disk two spreadsheets from Google Drive using file ID and prepared URL address.
This is main() from my C# code, there are no things outside of it:
public void Main()
{
string m_FileId = Dts.Variables["User::varFileId"].Value.ToString();
string m_RemoteUrl = "https://docs.google.com/spreadsheets/d/" + m_FileId + "/export?format=xlsx";
string m_FilePath = null;
WebClient client = new WebClient();
try
{
m_FilePath = Dts.Variables["User::varFilePath"].Value.ToString() + Dts.Variables["User::varFileName"].Value.ToString();
client.DownloadFile(new System.Uri(m_RemoteUrl), m_FilePath);
m_FilePath = "";
m_FileId = Dts.Variables["User::varFileId2"].Value.ToString();
m_RemoteUrl = "https://docs.google.com/spreadsheets/d/" + m_FileId + "/export?format=xlsx";
m_FilePath = Dts.Variables["User::varFilePath"].Value.ToString() + Dts.Variables["User::varFileName2"].Value.ToString();
client.DownloadFile(new System.Uri(m_RemoteUrl), m_FilePath);
}
catch(Exception e)
{
Dts.Events.FireError(0, "FileDownload", e.Message
+ "\r" + e.StackTrace
+ " \rUrl: " + m_RemoteUrl
+ " \rFilePath: " + m_FilePath
+ " \rPath: " + Dts.Variables["User::varFilePath"].Value.ToString()
+ " \rFileName2: " + Dts.Variables["User::varFileName2"].Value.ToString()
, string.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
Problem occurs exactly on every second time I run this code and I don't know how to get rid of it. There's just exception in my script task. I'm printing all variables that are used in this code, and as you can see there's something wrong with m_FilePath, it's like multiplied despite of being printed just once.
[FileDownload] Error: An exception occurred during a WebClient request.
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at ST_84b63d1593dd449886eb2b32dff40b2d.ScriptMain.Main()
Url: https://docs.google.com/spreadsheets/d/----------/export?format=xlsx
FilePath: C:\Google Drive extract\ga_manual_cost_file.xlsxC:\Google Drive extract\ga_manual_cost_file.xlsx
Path: C:\Google Drive extract\ga_manual_cost_file.xlsx
FileName2: ga_manual_cost_file.xlsx
SSIS variables that I'm using are ReadOnly, and are used only in this script task(I tried running only this part of control flow), and their values are as follows:

How to keep a process alive after remote PowerShell script completion?

I'm trying to start Zookeeper and Solr remotely via PowerShell scriptblock.
Then I see that the process is created in the remote machine (by checking the port 2181 of Zookeeper). And on the script completion it is being terminated.
How do I keep this alive even after the completion?
This code below stops the remote process on script completion. The script.ps1 does a lot of things that includes starting Zookeeper and Solr asJob.
int iRemotePort = 5985;
string strShellURI = #"http://schemas.microsoft.com/powershell/Microsoft.PowerShell";
string strAppName = #"/wsman";
WSManConnectionInfo ci = new WSManConnectionInfo(
false,
machineName,
iRemotePort,
strAppName,
strShellURI,
new PSCredential(userName, secure));
Runspace runspace = RunspaceFactory.CreateRunspace(ci);
runspace.Open();
using (PowerShell ps = PowerShell.Create())
{
session.Log(#"c:\temp\script.ps1 -serverID " + counter + " -copySolrConfig $" + status + " -currentHost \"" + machineName + "\" -IP_PORT_List \"" + String.Join(", ", machineWithPort) + "\"");
ps.Runspace = runspace;
ps.AddScript(#"c:\temp\script.ps1 -serverID " + counter + " -copySolrConfig $" + status + " -currentHost \"" + machineName + "\" -IP_PORT_List \"" + String.Join(", ", machineWithPort) + "\"");
var results = ps.Invoke();
foreach (var result in results)
{
session.Log(result.ToString());
}
}
runspace.Close();
So after a long try I came to a conclusion, Using power-shell script alive is not a appropriate way to keep zookeeper and solr running effectively. So moved it as a windows service and installed it on the remote machine via WiX.

CMD Commands won't run in C#

I'm trying to run the following:
String command = #"Rscript C:\Users\someone\Documents\generate_files.R " + fname + " " + folder;
System.Diagnostics.Process.Start("CMD.exe", "/K PATH C:\\Program Files\\R\\R-3.1.1\\bin;%path%");
System.Diagnostics.Process.Start("CMD.exe", "/K " + command);
Nothing happens when I execute it, does anyone know why? If I try
System.Diagnostics.Process.Start("CMD.exe", "/K MD TEST");
That works fine :s
e: Some extra info, The first command is setting the PATH so that the Rscript can be called by just typing Rscript. Also, both of these commands work when I do them in a normal CMD interface.
Prepare a batch file and execute it
using(StreamWriter sw = new StreamWriter("runscript.cmd", false))
{
sw.WriteLine(#"PATH C:\Program Files\R\R-3.1.1\bin;%path%");
sw.WriteLine(#"Rscript C:\Users\someone\Documents\generate_files.R " + fname + " " + folder);
}
System.Diagnostics.Process.Start("CMD.exe", "/K runscript.cmd");
This assumes that you have read/write permissions on the current directory. You can change the location to a more suitable position using
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string fileCmd = Path.Combine(path, "runscript.cmd");
using(StreamWriter sw = new StreamWriter(fileCmd, false)
....
As realised by Steve, I was running two console processes. To resolve this I simply ran both commands in the same process.
cmd.Arguments = "/K \"" + fullFilePath;
*try double " " right before PATH

Categories