Printing Issues on Railway Deployment: Permission Denied with smbclient
julibosch
HOBBYOP

2 years ago

I have my backend connected to a thermal printer, which works fine locally on my Windows PC. However, when I deploy it on Railway and attempt to print, I encounter the following error:

Failed to print. Command "smbclient '//railway/NictomImpresora' -c 'print -' -N -m SMB2" failed with exit code 127: sh: 1: smbclient: Permission denied

Could anyone suggest a solution for this?

Archived

4 Replies

brody
EMPLOYEE

2 years ago

How is the thermal printer hooked up to your code?


julibosch
HOBBYOP

2 years ago

My thermal printer is connected to a PHP backend via USB, this is the script,
$connector = new WindowsPrintConnector("NictomImpresora");

I downloaded a repository, which includes more code, but from what I understand, those are the connections for Linux and Windows.

protected function finalizeLinux($data)
{
/* Non-Windows samba printing / $device = "//" . $this -> hostname . "/" . $this -> printerName; if ($this -> userName !== null) { $user = ($this -> workgroup != null ? ($this -> workgroup . "\") : "") . $this -> userName; if ($this -> userPassword == null) { // No password $command = sprintf( "smbclient %s -U %s -c %s -N -m SMB2", escapeshellarg($device), escapeshellarg($user), escapeshellarg("print -") ); $redactedCommand = $command; } else { // With password $command = sprintf( "smbclient %s %s -U %s -c %s -m SMB2", escapeshellarg($device), escapeshellarg($this -> userPassword), escapeshellarg($user), escapeshellarg("print -") ); $redactedCommand = sprintf( "smbclient %s %s -U %s -c %s -m SMB2", escapeshellarg($device), escapeshellarg(""),
escapeshellarg($user),
escapeshellarg("print -")
);
}
} else {
// No authentication information at all
$command = sprintf(
"smbclient %s -c %s -N -m SMB2",
escapeshellarg($device),
escapeshellarg("print -")
);
$redactedCommand = $command;
}
$retval = $this -> runCommand($command, $outputStr, $errorStr, $data);
if ($retval != 0) {
throw new Exception("Failed to print. Command \"$redactedCommand\" " .
"failed with exit code $retval: " . trim($errorStr) . trim($outputStr));
}
}

protected function finalizeWin($data)
{
/* Windows-friendly printing of all sorts / if (!$this -> isLocal) { / Networked printing / $device = "\\" . $this -> hostname . "\" . $this -> printerName; if ($this -> userName !== null) { / Log in / $user = "/user:" . ($this -> workgroup != null ? ($this -> workgroup . "\") : "") . $this -> userName; if ($this -> userPassword == null) { $command = sprintf( "net use %s %s", escapeshellarg($device), escapeshellarg($user) ); $redactedCommand = $command; } else { $command = sprintf( "net use %s %s %s", escapeshellarg($device), escapeshellarg($user), escapeshellarg($this -> userPassword) ); $redactedCommand = sprintf( "net use %s %s %s", escapeshellarg($device), escapeshellarg($user), escapeshellarg("")
);
}
$retval = $this -> runCommand($command, $outputStr, $errorStr);
if ($retval != 0) {
throw new Exception("Failed to print. Command \"$redactedCommand\" " .
"failed with exit code $retval: " . trim($errorStr));
}
}
/* Final print-out / $filename = tempnam(sysgettempdir(), "escpos"); if ($filename === false) { throw new Exception("Failed to create temp file for printing."); } fileput_contents($filename, $data);
if (!$this -> runCopy($filename, $device)) {
throw new Exception("Failed to copy file to printer");
}
unlink($filename);
} else {
/
Drop data straight on the printer */
if (!$this -> runWrite($data, $this -> printerName)) {
throw new Exception("Failed to write file to printer at " . $this -> printerName);
}
}
}


brody
EMPLOYEE

2 years ago

I would think it goes without saying but you aren't going to be able to connect anything via USB to a Railway hosted service.


julibosch
HOBBYOP

2 years ago

Didn't know that, to be honest. I'm not very involved in thermal printing, I'm doing it because a friend asked me to. Is it possible via WiFi? Thanks for your help.


brody
EMPLOYEE

2 years ago

You would need to hook your thermal printer up to a IOT capable base station that can talk to your service on Railway over the internet (or vice versa)

Unfortunately I'll have to close this thread as it's quite off topic for what these help threads are intended for - platform help.

Please don't hesitate to open a new thread if you have any Railway specific questions!

Status changed to Archived brody almost 2 years ago


Loading...