Solved

Pathnames with blank space characters in Javascript - REPLACE and RUN arguments

Posted on 2010-11-20
14
809 Views
Last Modified: 2012-05-10
I use this code on an ASP page to run an excel spreadsheet on C:\Projetos Primavera  folder.

Could anyone help and show me the new code if I were to run C:\Arquivos de programas\Oracle\Primavera P6\Project Management\pm.exe?
What changes in the REPLACE and on the RUN arguments?

thanks


<script type="text/javascript">
var saprisco = 'file://C:/Projetos Primavera/saprisco.xls'.replace(/ /g,'%20');

function Run(commandtoRun, commandParms) {
  var oShell = new ActiveXObject("Shell.Application");
  oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");
  return false;
}
</script>
<a href="#" onclick="return Run('excel.exe',saprisco)">saprisco</a>
0
Comment
Question by:Roberth509
  • 6
  • 4
  • 2
  • +1
14 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34179907
No changes to run, just to the path

var saprisco = 'C:/Arquivos de programas/Oracle/Primavera P6/Project Management/pm.exe'.replace(/ /g,'%20');
0
 
LVL 58

Assisted Solution

by:cyberkiwi
cyberkiwi earned 500 total points
ID: 34179916
oops, I meant

var saprisco = 'file://C:/Arquivos de programas/Oracle/Primavera P6/Project Management/pm.exe'.replace(/ /g,'%20');

And you do need to change run:
<script type="text/javascript">
var saprisco = 'file://C:/Arquivos de programas/Oracle/Primavera P6/Project Management/pm.exe'.replace(/ /g,'%20');

function Run(commandtoRun, commandParms) {
  var oShell = new ActiveXObject("Shell.Application");
  oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");
  return false;
}
</script>
<a href="#" onclick="return Run(saprisco,'')">saprisco</a> 

Open in new window

0
 

Author Comment

by:Roberth509
ID: 34179968
An error msg appears saying Windows cannot find C:\Projetos%20Primavera\Oracle\Primavera%206\Project%20Management\pm.exe.

C:\Projetos Primavera\Oracle\Primavera P6\Project Management (copied from explorer)

I can assure you the file and pathnames are correct and exists ON MY CLIENT COMPUTER...not on the server...any idea what could be the problem?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:Roberth509
ID: 34179973
Sorry...my error msg was wrong...

The correct one is:

Windows cannot find C:\Projetos%20Primavera\Oracle\Primavera%20P6\Project%20Management\pm.exe.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34180051
do you use / or \ in your path?

My example was using the file://c:/....%20
0
 

Accepted Solution

by:
Roberth509 earned 0 total points
ID: 34180191
Thank you very much for you assistance...

I tried

<script type="text/javascript">
var saprisco = 'file://C:/Arquivos de programas/Oracle/Primavera P6/Project Management/pm.exe'.replace(/ /g,' ');

function Run(commandtoRun, commandParms) {
  var oShell = new ActiveXObject("Shell.Application");
  oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");
  return false;
}
</script>
<a href="#" onclick="return Run(saprisco,'')">saprisco</a>


AND IT WORKED!!!!!!!!

THANK YOU VERY MUCH....
0
 
LVL 5

Expert Comment

by:Zopilote
ID: 34180196
0
 
LVL 5

Expert Comment

by:Zopilote
ID: 34180703
happy you found the solution, could you post it?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34180791
You changed space to space...

Very inefficient ;)
0
 

Author Comment

by:Roberth509
ID: 34180797
Sure...it was posted above...I changed the replace argument...

Here it goes again

<script type="text/javascript">
var saprisco = 'file://C:/Arquivos de programas/Oracle/Primavera P6/Project Management/pm.exe'.replace(/ /g,' ');

function Run(commandtoRun, commandParms) {
  var oShell = new ActiveXObject("Shell.Application");
  oShell.ShellExecute(commandtoRun, commandParms, "", "open", "1");
  return false;
}
</script>
<a href="#" onclick="return Run(saprisco,'')">saprisco</a>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34180800
So just use


var saprisco = 'file://C:/Arquivos de programas/Oracle/Primavera P6/Project Management/pm.exe'

since


.replace(/ /g,' ');
changes all spaces to spaces
0
 

Author Closing Comment

by:Roberth509
ID: 34211305
With hints provided, I ended up finding silution myself
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34211652
Still does not make any sense
0
 

Author Comment

by:Roberth509
ID: 34215183
mplungjan,

I agree totally that it does not make any sense....
I do feel not qualified to justify at this point, but I will post here the result of several tests I will do tomorrow.
My 'smart' solution of replacing space with space works with

"C:\Arquivos de programas\Oracle\Primavera P6\Project Management\PM.exe", but not with

"C:\Arquivos de programas\Oracle\Primavera Risk Analysis\PrimaveraRiskAnalysis.exe"





0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question