Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Passing parameter into batch file, and the parameter is a variable that holds a filepath
Forum Updated to NodeBB v4.3 + New Features

Passing parameter into batch file, and the parameter is a variable that holds a filepath

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pditty8811
    wrote on 5 Jan 2014, 06:38 last edited by
    #1

    I'm calling a batch file from my qt program and am passing parameters. The batch file is set up correctly, I've pasted the code at the bottom. Below I have the section of my qt program that is the issue. The second parameter that I am passing is a variable of a filepath "sh3InstallLocation". But I am unable to pass it in. I get error with the batch. but if I change the value of sh3InstallLocation to something like "words" then everything works. Not sure what the issue is.

    @
    QString sh3InstallLocation;
    sh3InstallLocation = ui->lineEdit_SH3Install->text();
    sh3InstallLocation.replace(("\"), ("\\"));
    QProcess p;
    QStringList abc;
    abc << "/K" << "C:\Documents and Settings\Shirin\My Documents\Dropbox\SH3 Files\SH3DC Installer\SH3DC_Installer\1.bat" << sh3InstallLocation;

        p.startDetached("cmd.exe", abc);
    

    @

    Batch:
    @echo off

    SETLOCAL ENABLEDELAYEDEXPANSION

    set money=%1
    set nomoney=%2
    set moremoney=%3
    echo money: !money!
    echo nomoney: !nomoney!
    echo moremoney: !moremoney!
    echo done
    pause

    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 5 Jan 2014, 10:29 last edited by
      #2

      Why do you replace \ with \? If the lineedit contains text "c:\whatever" you don't need to escape it to pass it to cmd.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        pditty8811
        wrote on 5 Jan 2014, 18:27 last edited by
        #3

        [quote author="Chris Kawa" date="1388917768"]Why do you replace \ with \? If the lineedit contains text "c:\whatever" you don't need to escape it to pass it to cmd.[/quote]

        This has nothing to do with my issue.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 5 Jan 2014, 20:01 last edited by
          #4

          Well I don't have a magic 8-ball you know ;) You haven't really said what the issue is so I tried to best guess it.

          What do you mean by " I am unable to pass it in. I get error with the batch."
          You just did pass it in so you are able to. What kind of error do you get? How do you get it? Is it a runtime error, a message on the standard error stream or just a different output from what you expect?

          An answer can only be as good as the question is.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pditty8811
            wrote on 10 Jan 2014, 21:21 last edited by
            #5

            How should I send the parameter to the batch file with spaces in my file path, that I'm sending as a parameter?

            1 Reply Last reply
            0

            1/5

            5 Jan 2014, 06:38

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved