Convert DOC to PDF using unoconv via Symfony Component - symfony

I'm trying to convert word documents to PDF, via the commandline using unoconv via PHP.
I'm using the Symfony Process Component to run the command via the command line.
public function run()
{
$cmd = 'unoconv --listener & unoconv ' . $this->path;
//Tested this to check for permissions and this worked.
//$cmd = 'touch /vagrant/public/testfile.pdf';
$process = new Process($cmd);
$process->run();
return $process->getOutput();
}
This yields no output, and doesn't convert the file. However if I echo the $cmd and paste it into the CLI it converts the file as expected and logs output as it goes.
Any ideas what could be the problem?
Edit:
I've since tried: calling mustRun() & start() methods on the symfony class.
mustRun() gives the following error:
"The command '//command//' failed. Exit Code: 251(Unknown error) Output: ================ Error Output: ================
After adding the log code as suggested by Diego Ferri, I get Error: Unable to connect or start own listener. Aborting. in the log file; but I can't find much online that's helpful for that.

Please read this section but also check the troubleshooting section.
It is possible that the shell is missing some important environment variables for unoconv/LibreOffice to work properly (PATH, HOME, ...). And it is recommended you call the LibreOffice python binary with unoconv instead of leaving it up to unoconv to determine the location of LibreOffice and python.

Related

How to source a remote file hosted on gitlab in R?

I have an internal repository on Gitlab.
In my R script I want to source an .R file from that internal repository.
Normally I can source a publicly available R script with the following code
source("public-path-to-file")
But When I try to do that with a private file I get:
Error in source("") :
:1:1: unexpected '<'
1: <
^
I found a hacky way to do it that at least gets things done:
First you need to create a private token with api access. Then you can call gitlab's API directly to GET the file
Code:
cmd <- "curl -s --header 'PRIVATE-TOKEN: <your private token for gitlab with api access>' '<full gitlab link of the raw file that you want to source>'" # you directly access the API with your private token
output <- system(cmd, intern=TRUE) # capturing the output of the system call
writeLines(output, "functions.R") # creating a temporary file which contains the output of the API call
source("functions.R") # Sourcing the file the usual way
file.remove("functions.R") # removing the temporary file for housekeeping
Explanation:
We call the API directly with a GET request using the system command curl.
Then you call the system command through R, capturing the result.
And then you can create a temporary file with the respective contents and source it as you would normally do. Hope this may help someone

asp.net core executing powershell some commands work while others return result 0

I have the following simple code that works and executes a powershell command in asp.net core website running on my cshtml.cs code behind page
using System.Management.Automation;
public void Execute()
{
using (var ps = PowerShell.Create())
{
ps.AddScript("Get-Date");
var results = ps.Invoke();
foreach (var result in results)
{
string test = result.ToString();
}
}
}
This works i get the current date reported as a string and results variable contains a count of 1.
"7/16/2020 4:38:27 PM"
If i then change it to another command say
ps.AddScript("Get-WmiObject");
or
ps.AddScript("Get-LocalGroupMember -group my_local_group_name");
Then i get no results, results comes back as count of 0 ?? The only thing i can determine is that Get-Date is a single string where as the other commands Get-WmiObject and Get-LocalGroupMember are multiple lines of text in the outputs when i execute them from a normal Powershell window.
my goal is to be able to execute the Get-LocalGroupMember command and get it's output. Is there something else i'm missing or not doing in terms of Powershell commands ? why is it some commands are working and producing output and others are not ?
UPDATE:
So i was getting error in the error stream of the ps object it states
{The 'Get-LocalGroupMember' command was found in the module 'Microsoft.PowerShell.LocalAccounts', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.LocalAccounts'.}
if i open a x86 Powershell window and run the Get-LocalGroupMember cmd it gives me error
Get-LocalGroupMember : The term 'Get-LocalGroupMember' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
running the Get-LocalGroupMember cmd in a regular Powershell window (that is x64) the cmd runs perfect.
My project is set to x64 :( so am failing to understand why asp.net is using what seems to me a 32bit version of powershell. That's what i need i need to be able to execute my powershell cmds as x64 because Get-LocalGroupMember cmd is only available in Powershell x64 .
Please Help ? thanks
so i ended up having to do the following for some reason in order to get certian commands like Get-LocalGroupMember to work, other commands like Get-Date don't require the import, and even though on my system i had execution policy unrestricted, whenever i use c# in asp.net and checked errors on my ps object it was acting like it wasn't and would not let me run a script using AddScript. So i had to be administrator running visual studio and use set-executionpolicy like below, then be able to add the localaccounts module to be able to use Get-LocalGroupMember.. again if i open a x64 Powershell window on the system i can run Get-LocalGroupMember fine. seems c# is doing some weird things with the Powershell shell that it is creating and running in memory. Anyway hopefully this saves someone else time if they run into the same situation.
using (var ps = PowerShell.Create())
{
ps.AddScript("Set-ExecutionPolicy Unrestricted -force");
ps.AddScript("Import-Module Microsoft.PowerShell.LocalAccounts");
ps.AddScript("Get-LocalGroupMember -group your_local_group_name | Out-String");
var results = ps.Invoke();
foreach (var result in results)
{
string test = result.ToString();
TestText = test;
}
}

Error while running a .sh script via QProcess

I have written a QT GUI program where pressing a button will execute a .sh script. The contents of the script is-
echo -e 'attach database 'testdatabase.db' as 'aj';\n.separator ","\n.import ora_exported.csv qt_ora_exported' | sqlite3 testdatabase.db
basically the script will import a .csv to an sqlite database. And when the script file (script.sh) is run manually from linux terminal ($./script.sh) it successfully imports the .csv file into the database table.
But, when I call the script from my QT program
void MainWindow::on_importButton_clicked()
{
QProcess process;
process.startDetached("/bin/sh",QStringList()<<"/home/aj/script.sh");
}
it compiles successfully but gives an error message in console when the button is pressed at runtime.
Error: near line 1: near "-": syntax error
Error: cannot open "ora_exported.csv"
what could be causing this ???
EDITED
I have changed my .sh script now to--
echo -e 'attach database 'testdatabase.db' as 'aj';\n.separator ","\n.import /home/aj/ora_exported.csv qt_ora_exported' | sqlite3 testdatabase.db
Thus providing the path to my ora_exported.csv. As a result the runtime error [Error: cannot open "ora_exported.csv"] has gone but the other message [Error: near line 1: near "-": syntax error] is still coming.
Same as was observed in previous case, using ./script.sh is successfully importing data to sqlite3 db table file but QProcess is unable to.
echo is a built in command of a shell that may behave differently.
E.g. take this test script: echotest.sh
echo -e "123"
Now we can compare different results:
$ bash echotest.sh
123
$ zsh echotest.sh
123
$ dash echotest.sh
-e 123
You are probably on some Ubuntu-like OS, where /bin/sh redirects to dash. That would explain the error around "-". So if you are using echo, set you shell specificially or ensure that your script works on all common shells.
Additionally, you are messing up your quotations
echo -e 'attach database 'testdatabase.db' as 'aj';\n.separator ","\n.import /home/aj/ora_exported.csv qt_ora_exported'
results in (no quotations in the first line)
attach database testdatabase.db as aj;
.separator ","
.import /home/aj/ora_exported.csv qt_ora_exported
but you pobably want
echo -e "attach database 'testdatabase.db' as 'aj';\n.separator ','\n.import /home/aj/ora_exported.csv qt_ora_exported"
It looks strange that you are using external script to update database!
why you don't pass "ora_exported.csv" file name as a script argument? This would help solve the problem.
I was talking (typing) about this solution:
void MainWindow::on_importButton_clicked()
{
QProcess::startDetached("/bin/sh",
QStringList()<<"/home/aj/script.sh",
"<location of: 'ora_exported.csv' file>");
}

unable to execute unix script using . script_name

I am unable to execute following command in unix as
e.g. ->
export ENVFILE=$PARENT_DIR/../env/.tpms.evr
while i try to execute . "${ENVFILE}" it shows me error as bash: 39910-: command not found
can anybody let me know about how to fix this.
You most probably have a line in .tpms.evr script which bash tries to execute as a command called "39910-"
Please share this .tpms.evr script or just that line containing "39910-"

Installing an MSP using Powershell works on the local machine, fails remotely. Why?

I need some Powershell advice.
I need to install an application's MSP update file on multiple Win08r2 servers. If I run these commands locally, within the target machine's PS window, it does exactly what I want it to:
$command = 'msiexec.exe /p "c:\test\My Application Update 01.msp" REBOOTPROMPT=S /qb!'
invoke-wmimethod -path win32_process -name create -argumentlist $command
The file being executed is located on the target machine
If I remotely connect to the machine, and execute the two commands, it opens two x64 msiexec.exe process, and one msiexec.exe *32 process, and just sits there.
If I restart the server, it doesn't show that the update was installed, so I don't think it's a timing thing.
I've tried creating and remotely executing a PS1 file with the two lines, but that seems to do the same thing.
If anyone has advice on getting my MSP update installed remotely, I'd be all ears.
I think I've included all the information I have, but if something is missing, please ask questions, and I'll fill in any blanks.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
My process for this is:
Read a CSV for server name and Administrator password
Create a credential with the password
Create a new session using the machine name and credential
Create a temporary folder to hold my update MSP file
Call a PS1 file that downloads the update file to the target server
>>> Creates a new System.Net.WebClient object
>>> Uses that web client object to download from the source to the location on the target server
Call another PS1 file that applies the patch that was just downloaded –>> This is where I’m having issues.
>>> Set the variable shown above
>>> Execute the file specified in the variable
Close the session to the target server
Move to the next server in the CSV…
If I open a PS window and manually set the variable, then execute it (as shown above in the two lines of code), it works fine. If I create a PS1 file on the target server, containing the same two lines of code, then right click > ‘Run With PowerShell’ it works as expected / desired. If I remotely execute my code in PowerGUI, it returns a block of text that looks like this, then just sits there. RDP’d into the server, the installer never launches. My understanding of the “Return Value” value is that “0″ means the command was successful.
PSComputerName : xx.xx.xx.xx
RunspaceId : bf6f4a39-2338-4996-b75b-bjf5ef01ecaa
PSShowComputerName : True
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ProcessId : 4808
ReturnValue : 0
I even added a line of code between the variable and the execution that creates a text file on the desktop, just to verify I was getting into my ‘executeFile’ file, and that text file does get created. It seems that it’s just not remotely executing my MSP.
Thank you in advance for your assistance!
Catt11.
Here's the strategy I used to embed an msp into a powershell script. It works perfectly for me.
$file = "z:\software\AcrobatUpdate.msp"
$silentArgs = "/passive"
$additionalInstallArgs = ""
Write-Debug "Running msiexec.exe /update $file $silentArgs"
$msiArgs = "/update `"$file`""
$msiArgs = "$msiArgs $silentArgs $additionalInstallArgs"
Start-Process -FilePath msiexec -ArgumentList $msiArgs -Wait
You probably don't need to use the variables if you don't want to, you could hardcode the values. I have this set up as a function to which I pass those arguments, but if this is more of a one-shot deal, it might be easier to hard-code the values.
Hope that helps!
using Start-Process for MSP package is not a good practice because some update package lockdown powershell libs and so you must use WMI call

Resources