Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Visual Studio 2017: Shell command

Options
  • 02-03-2018 11:40am
    #1
    Registered Users Posts: 669 ✭✭✭


    Hi

    I'm using Visual Studio 2017 and I want to use the Shell command to convert an XLS file to CSV using LibreOffice. It's part of a bigger solution.

    Something like:

    ShellRet = Shell("""" & "C:\Program Files (x86)\LibreOffice 5\program\soffice.exe" & """")

    works fine, opening LibreOffice. I can go further:

    ShellRet = Shell("""" & "C:\Program Files (x86)\LibreOffice 5\program\soffice.exe" & """" & " Test.xls")

    also works, opening the file as expected but when I use the command line to convert the file

    ShellRet = Shell("""" & "C:\Program Files (x86)\LibreOffice 5\program\soffice.exe" & """" & " --convert-to csv C:\Test.xls"

    nothing happens. The programme appears to pause but no file is created. I've put the command into a batch file and when the

    batch file is run, the file is converted as expected. Even if I use the Shell command to run the batch file, it doesn't work.

    Am I missing something stupidly obvious?

    TIA


Comments

  • Registered Users Posts: 7,157 ✭✭✭srsly78


    Missing that vs2017 isn't a programming language.

    You tested it from command line and it doesn't work either? So fix that first before you try to automate it.

    You need to capture output from the command to see what went wrong.


  • Registered Users Posts: 669 ✭✭✭galvo_clare


    Alright, .NET Basic.

    It does work from the command line and that’s what I detailed in my original post. I can run the batch file from a command prompt and it works. If I call the batch file from VS it doesn’t. It doesn’t seem to be producing any error messages.

    srsly78 wrote: »
    Missing that vs2017 isn't a programming language.

    You tested it from command line and it doesn't work either? So fix that first before you try to automate it.

    You need to capture output from the command to see what went wrong.


  • Registered Users Posts: 7,157 ✭✭✭srsly78


    You have to capture the output in a certain way, look at documentation for Shell() command. It will always return something.

    Also try assembling the command in a string, and then inspect it for errors before passing to Shell().


  • Registered Users Posts: 669 ✭✭✭galvo_clare


    Hi

    Yes, I’m assembling a string so I know that what I’m sending is what I think I’m sending.
    I’ll have a look at the Shell documentation and see what I can find.

    srsly78 wrote: »
    You have to capture the output in a certain way, look at documentation for Shell() command. It will always return something.

    Also try assembling the command in a string, and then inspect it for errors before passing to Shell().


  • Registered Users Posts: 7,157 ✭✭✭srsly78


    That may not be the case. It's likely the problem is related to white-space somehow.

    You have one string that works, and another that doesn't. Closely look at the difference.


  • Advertisement
  • Registered Users Posts: 14,331 ✭✭✭✭jimmycrackcorm


    For starters you should be using escaped quotes as all those " makes for uncomfortable reading.
    Try running the batch file via shell - see if that works.
    However, I would have thought that Process would be the preferable option.


  • Registered Users Posts: 669 ✭✭✭galvo_clare


    Hi

    Good point about the escaped quotes. Must take that up.

    As I said, I did try running the batch via shell and it doesn't work.

    I'll explore Process and see if that's a runner. Thanks.
    For starters you should be using escaped quotes as all those " makes for uncomfortable reading.
    Try running the batch file via shell - see if that works.
    However, I would have thought that Process would be the preferable option.


Advertisement